Maps issues on android

I’m having trouble getting the marker added. (only tried on Android devices) I want to add the marker inmediately after the map is loaded. Got it working adding a delay but couldn’t make it work by just adding the marker or scaling the map again (by using setRegion).

I tried the following:

local mapa mapa=native.newMapView( 20, 20, 280, 360 ) mapa.x = display.contentCenterX mapa.y = display.contentCenterY mapa.mapType = "standard" mapa:setCenter( 41.641208, -0.896030 ) mapa:addMarker(tonumber(41.641208), tonumber(-0.896030),{ title = "El Rincon de la Encina", subtitle = "Ofertas diarias!"}) mapa:setRegion(41.641208, -0.896030, 0.01, 0.01, false) mapa.isLocationVisible=true
  1. This one works correctly but takes far too many resources

    local mapa mapa=native.newMapView( 20, 20, 280, 360 ) mapa.x = display.contentCenterX mapa.y = display.contentCenterY mapa.mapType = “standard” mapa:setCenter( 41.641208, -0.896030 ) mapa.isLocationVisible=true local function listener:timer( event ) mapa:addMarker(tonumber(41.641208), tonumber(-0.896030),{ title = “El Rincon de la Encina”, subtitle = “Ofertas diarias!”}) end timer.performWithDelay( 30000, listener )

Only if the timer calls the function after the map is loaded I get the wanted result.

The reason for adding tonumber was to make sure Corona got the number correctly.

 

local myMap = native.newMapView( 20, 20, 280, 360 ) myMap.x = display.contentCenterX local attempts = 0 local rinconEncinaLocation={     latitude=41.641208,     longitude=0.896030     } local function newmap(event) myMap:setCenter( rinconEncinaLocation.latitude, rinconEncinaLocation.longitude )         myMap:addMarker( rinconEncinaLocation.latitude, rinconEncinaLocation.longitude ) end 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 )             --native.showAlert( "No GPS Signal", "Can't sync with GPS.", { "Okay" } )         end     else        newmap() end end

Hi @gabryg29,

It appears that you copied the example from here…

http://docs.coronalabs.com/api/type/Map/getUserLocation.html

…but then you changed the logic, which I don’t recommend.

I think you should use the example and, in place of this line:

[lua]

    myMap:addMarker( currentLocation.latitude, currentLocation.longitude )

[/lua]

Do something like this…

[lua]

    myMap:addMarker( rinconEncinaLocation.latitude, rinconEncinaLocation.longitude )

[/lua]

Hope this helps,

Brent

Hi @gabryg29,

It appears that you copied the example from here…

http://docs.coronalabs.com/api/type/Map/getUserLocation.html

…but then you changed the logic, which I don’t recommend.

I think you should use the example and, in place of this line:

[lua]

    myMap:addMarker( currentLocation.latitude, currentLocation.longitude )

[/lua]

Do something like this…

[lua]

    myMap:addMarker( rinconEncinaLocation.latitude, rinconEncinaLocation.longitude )

[/lua]

Hope this helps,

Brent