【发布时间】:2015-05-04 00:55:06
【问题描述】:
我无法添加标记。 (仅在 Android 设备上尝试过)我想在地图加载后立即添加标记。让它工作添加延迟,但不能通过添加标记或再次缩放地图(通过使用setRegion)使其工作。
我尝试了以下方法:
1.
本地地图
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
2。这个工作正常
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 )
只有在加载地图后计时器调用该函数时,我才会得到想要的结果。
添加tonumber 的原因是为了确保 Corona 得到正确的号码。
-
应用@AniV 提供的解决方案
本地尝试 = 0
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:setRegion(41.641208, -0.896030, 0.01, 0.01, false) mapa.isLocationVisible=true local function locationHandler( event ) local currentLocation = myMap:getUserLocation() local rinconEncinaLat = 41.641208 local rinconEncinaLon=-0.896030 if ( currentLocation.errorCode or ( currentLocation.latitude == 0 and currentLocation.longitude == 0 ) ) then attempts = attempts + 1 if ( attempts > 10 ) then native.showAlert( "No GPS Signal", "Can't sync with GPS.", { "Okay" } ) else timer.performWithDelay( 2000, locationHandler ) end else mapa:setCenter( rinconEncinaLat, rinconEncinaLon ) mapa:addMarker( rinconEncinaLat, rinconEncinaLon,{ title = "El Rincon de la Encina", subtitle = "Ofertas diarias!"}) end end locationHandler()
感谢您的帮助。
【问题讨论】:
标签: android google-maps lua coronasdk marker