addMarker does not show the PIN image

I am trying to display a PIN image (default or not) on a map.

I am using the build: 2018.3392 and I have a google APIKEY configured for the maps in config.lua

I can not display the PIN image (And without options it should show the default pin).

This is the code (taken from the coronasdk site and modified slightly)

What I can be doing wrong?  

-- Map marker listener function 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 end -- Create a native map view local myMap = native.newMapView( 0, 0, 300, 220 ) myMap.x = display.contentCenterX myMap.y = display.contentCenterY myMap:setRegion( 4.7125902737478,-74.071590273748, 0.01, 0.01, false ) myMap:setCenter( 4.7125902737478,-74.071590273748 ) -- Sometime later (following activation of device location hardware) local options = { title = "Displayed Title", subtitle = "Subtitle text", listener = markerListener, -- This will look in the resources directory for the image file imageFile = "someImage.png", --{ filename = "someImage.png", baseDir = system.ResourcesDirectory }, -- Alternatively, this looks in the specified directory for the image file -- imageFile = { filename="someImage.png", baseDir=system.TemporaryDirectory } } --local result, errorMessage = myMap:addMarker( 4.7125902737478,-74.071590273748, options ) local result, errorMessage = myMap:addMarker( 4.7125902737478,-74.071590273748) if ( result ) then print( "Marker added" ) else print( errorMessage ) end

The result in attached image.

Regards and thanks in advance for your answers,

Solón

Have you looked at your device’s console log (with adb logcat) to see if you’re getting any error messages?

Rob

Thanks for answering Rob.

Yes, I’m doing that and this is the answer:

XT1058: Platform: XT1058 / ARM Neon / 5.1 / Adreno (TM) 320 / OpenGL ES 3.0 V@84.0 AU@05.00.02.006.020 (CL@) / 2018.3392 / English | US | en\_US | en XT1058: Marker added

and with adb:

V/Corona (11339): \> Class.forName: network.LuaLoader V/Corona (11339): \< Class.forName: network.LuaLoader V/Corona (11339): Loading via reflection: network.LuaLoader I/Corona (11339): Platform: XT1058 / ARM Neon / 5.1 / Adreno (TM) 320 / OpenGL ES 3.0 V@84.0 AU@05.00.02.006.020 (CL@) / 2018.3392 / English | US | en\_US | en V/Corona (11339): \> Class.forName: \_Corona\_Build\_Number.LuaLoader V/Corona (11339): \> Class.forName: shared.google.play.services.base.LuaLoader V/Corona (11339): \> Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona (11339): \< Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona (11339): Loading via reflection: CoronaProvider.licensing.google.LuaLoader V/Corona (11339): \> Class.forName: \_CoronaSetup.LuaLoader I/Corona (11339): Marker added

If you have directly copied and pasted that code, even though you’ve changed the latitude and longitude and a few other parameters, it’s likely not going to work.  Did you notice this comment:

  1. – Sometime later (following activation of device location hardware)

If you just run that code directly, there is a good chance that the device’s GPS/Location Services hasn’t enabled yet. Code executes in microseconds but it can take multiples of seconds to get the location hardware engaged. This means if that’s your code, you’re adding the map marker before the system can manage it.

Try putting your add marker code inside a timer of a few seconds or if you look at our Business App sample’s map code:

https://github.com/coronalabs-samples/business-app-sample/blob/master/mapscene.lua

You will see that there we do a requestLocation() API call which generates an event that calls the addMarker() code once it’s geocoded the address.

Rob

Thanks Rob.

Excellent and simple solution. It worked perfectly. Here is the code:

local function delayForMarker( ... ) --local result, errorMessage = myMap:addMarker( 4.7125902737478,-74.071590273748, options ) local result, errorMessage = myMap:addMarker( 4.7125902737478,-74.071590273748) if ( result ) then print( "Marker added" ) else print( errorMessage ) end end timer.performWithDelay( 2000, delayForMarker )

Have you looked at your device’s console log (with adb logcat) to see if you’re getting any error messages?

Rob

Thanks for answering Rob.

Yes, I’m doing that and this is the answer:

XT1058: Platform: XT1058 / ARM Neon / 5.1 / Adreno (TM) 320 / OpenGL ES 3.0 V@84.0 AU@05.00.02.006.020 (CL@) / 2018.3392 / English | US | en\_US | en XT1058: Marker added

and with adb:

V/Corona (11339): \> Class.forName: network.LuaLoader V/Corona (11339): \< Class.forName: network.LuaLoader V/Corona (11339): Loading via reflection: network.LuaLoader I/Corona (11339): Platform: XT1058 / ARM Neon / 5.1 / Adreno (TM) 320 / OpenGL ES 3.0 V@84.0 AU@05.00.02.006.020 (CL@) / 2018.3392 / English | US | en\_US | en V/Corona (11339): \> Class.forName: \_Corona\_Build\_Number.LuaLoader V/Corona (11339): \> Class.forName: shared.google.play.services.base.LuaLoader V/Corona (11339): \> Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona (11339): \< Class.forName: CoronaProvider.licensing.google.LuaLoader V/Corona (11339): Loading via reflection: CoronaProvider.licensing.google.LuaLoader V/Corona (11339): \> Class.forName: \_CoronaSetup.LuaLoader I/Corona (11339): Marker added

If you have directly copied and pasted that code, even though you’ve changed the latitude and longitude and a few other parameters, it’s likely not going to work.  Did you notice this comment:

  1. – Sometime later (following activation of device location hardware)

If you just run that code directly, there is a good chance that the device’s GPS/Location Services hasn’t enabled yet. Code executes in microseconds but it can take multiples of seconds to get the location hardware engaged. This means if that’s your code, you’re adding the map marker before the system can manage it.

Try putting your add marker code inside a timer of a few seconds or if you look at our Business App sample’s map code:

https://github.com/coronalabs-samples/business-app-sample/blob/master/mapscene.lua

You will see that there we do a requestLocation() API call which generates an event that calls the addMarker() code once it’s geocoded the address.

Rob

Thanks Rob.

Excellent and simple solution. It worked perfectly. Here is the code:

local function delayForMarker( ... ) --local result, errorMessage = myMap:addMarker( 4.7125902737478,-74.071590273748, options ) local result, errorMessage = myMap:addMarker( 4.7125902737478,-74.071590273748) if ( result ) then print( "Marker added" ) else print( errorMessage ) end end timer.performWithDelay( 2000, delayForMarker )