map Listener events not working

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?

Did you ever find an answer to this @FearTec?

Nope

The problem is the Map listeners are not initialize like other event listeners. You include the listener function in the Map request instead of calling AddEventListener. This is clearly shown in the MapView sample app and the Map event documentation.

http://docs.coronalabs.com/api/event/mapLocation/index.html

And it works as advertised. The sample app is a good reference.

Thanks Tom!

After going back and looking again I got it working:

if ( myMap ) then

   – Display a normal map with vector drawings of the streets.

   – Other mapType options are “satellite” and “hybrid”.

   myMap.mapType = “normal”

   myMap.x = display.contentCenterX

   myMap.y = display.contentCenterY

   – Initialize map to a real location, since default location (0,0) is not very interesting

   myMap:setCenter( 37.331692, -122.030456 )

   – This is returned as a mapLocation event

   local function mapLocationListener(event)

       print("map tapped latitude: ", event.latitude)

       print("map tapped longitude: ", event.longitude)

       native.showAlert( “Map Clicked”, “show where…”, { “OK” } )

   end

   myMap:addEventListener(“mapLocation”, mapLocationListener)

end

Did you ever find an answer to this @FearTec?

Nope

The problem is the Map listeners are not initialize like other event listeners. You include the listener function in the Map request instead of calling AddEventListener. This is clearly shown in the MapView sample app and the Map event documentation.

http://docs.coronalabs.com/api/event/mapLocation/index.html

And it works as advertised. The sample app is a good reference.

Thanks Tom!

After going back and looking again I got it working:

if ( myMap ) then

   – Display a normal map with vector drawings of the streets.

   – Other mapType options are “satellite” and “hybrid”.

   myMap.mapType = “normal”

   myMap.x = display.contentCenterX

   myMap.y = display.contentCenterY

   – Initialize map to a real location, since default location (0,0) is not very interesting

   myMap:setCenter( 37.331692, -122.030456 )

   – This is returned as a mapLocation event

   local function mapLocationListener(event)

       print("map tapped latitude: ", event.latitude)

       print("map tapped longitude: ", event.longitude)

       native.showAlert( “Map Clicked”, “show where…”, { “OK” } )

   end

   myMap:addEventListener(“mapLocation”, mapLocationListener)

end