When I click on a maker I then click the default button to remove it. This seems to work but only evenryother one will delete I am not sure where I am going wrong. The button is at the end of the code. Any help would be appreciated.
-- Create a native map view local myMap = native.newMapView( 20, 20, 280, 360 ) myMap.x = display.contentCenterX local function markerListener(event) print( "type: ", event.type ) -- event type print( "markerId: ", event.markerId ) -- ID of the marker that was touched print( "lat: ", event.latitude ) -- latitude of the marker print( "long: ", event.longitude ) -- longitude of the marker ID = event.markerId lat = event.latitude lon = event.longitude local myText = display.newText( ID, 200, 300, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) end local options = { title = "Displayed Title", subtitle = "Subtitle text", listener = markerListener, } local attempts = 0 local locationText = display.newText( "Location: ", 0, 400, native.systemFont, 16 ) locationText.anchorY = 0 locationText.x = display.contentCenterX local function locationHandler( event ) local currentLocation = myMap:getUserLocation() if ( currentLocation.errorCode or ( currentLocation.latitude == 0 and currentLocation.longitude == 0 ) ) then locationText.text = currentLocation.errorMessage attempts = attempts + 1 if ( attempts \> 10 ) then native.showAlert( "No GPS Signal", "Can't sync with GPS.", { "Okay" } ) else timer.performWithDelay( 1000, locationHandler ) end else locationText.text = "Current location: " .. currentLocation.latitude .. "," .. currentLocation.longitude myMap:setCenter( currentLocation.latitude, currentLocation.longitude ) myMap:addMarker( currentLocation.latitude, currentLocation.longitude ) end end locationHandler() local function mapMarkerListener( event ) markerID = myMap:addMarker(event.latitude, event.longitude,options) return true end myMap:addEventListener( "mapLocation", mapMarkerListener ) local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then myMap:removeMarker(ID) end end -- Create the widget local button1 = widget.newButton( { left = 50, top = 200, id = "button1", label = "Default", onEvent = handleButtonEvent } )