I can’t seem to get the three map events to work
Code at the top of the lua page.
local myMap = native.newMapView( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) local function mapMarkerListener(event) DoPrint( event.type, event.markerId, event.latitude, event.longitude) end local function mapTapListener( event ) native.showAlert( "Map Tapped", "The tapped location is in: " .. event.latitude .. ", " .. event.longitude, { "OK" } ) end local function mapLocationListener( event ) native.showAlert( "Map Marker Tapped", "The tapped marker location is: " .. event.latitude .. " - " .. event.longitude .. ", id: " .. tostring(event.markerid), { "OK" } ) end
Code at the bottom of the page.
if ( myMap ) then -- Other mapType options are "satellite" and "hybrid". myMap.mapType = "normal" -- Display a normal map with vector drawings of the streets. myMap.x = display.contentCenterX myMap.y = display.contentCenterY -- Initialize map to a real location, since default location (0,0) is not very interesting myMap:removeAllMarkers() -- Remove Markers myMap:setCenter( -31.090927, 150.930005 ) -- Set Over Tamworth myMap:setRegion( -31.090927, 150.930005, 0.5, 0.5, false ) -- Change to set Initial Zoom Level myMap.isVisible = false myMap:addEventListener("mapMarker", mapMarkerTappedListener) myMap:addEventListener("mapTap", mapTapListener) myMap:addEventListener("mapLocation", mapLocationListener) end
Nothing gets fired in the map on a device.
I have even tried the following but get Assertion failed.
Runtime:addEventListener("mapMarker", mapMarkerTappedListener) Runtime:addEventListener("mapTap", mapTapListener) Runtime:addEventListener("mapLocation", mapLocationListener)
Ideas?