Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

addMarker does not show the PIN image
Started by solca Oct 04 2018 09:12 AM

5 replies to this topic
map addmarker native newmapview

Best Answer solca , 05 October 2018 - 04:59 PM

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 )

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

solca

[GLOBAL: userInfoPane.html]
solca
  • Enthusiast

  • 48 posts
  • Corona SDK

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

 

Attached Files



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,714 posts
  • Corona Staff

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

 

Rob



[TOPIC: post.html]
#3

solca

[GLOBAL: userInfoPane.html]
solca
  • Enthusiast

  • 48 posts
  • Corona SDK

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


[TOPIC: post.html]
#4

solca

[GLOBAL: userInfoPane.html]
solca
  • Enthusiast

  • 48 posts
  • Corona SDK

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

 

Rob

 

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


[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,714 posts
  • Corona Staff

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



[TOPIC: post.html]
#6

solca

[GLOBAL: userInfoPane.html]
solca
  • Enthusiast

  • 48 posts
  • Corona SDK

  Best Answer

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 )



[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: map, addmarker, native, newmapview