在Android的Corona SDK中添加标记
我在添加标记时遇到困难。(仅在Android设备上试用)我想在地图加载后立即添加标记。添加一个延迟,但仅仅添加标记或再次缩放地图(使用在Android的Corona SDK中添加标记,android,google-maps,lua,coronasdk,marker,Android,Google Maps,Lua,Coronasdk,Marker,我在添加标记时遇到困难。(仅在Android设备上试用)我想在地图加载后立即添加标记。添加一个延迟,但仅仅添加标记或再次缩放地图(使用setRegion)无法使其工作 我尝试了以下方法: 一, 局部映射 mapa=native.newMapView( 20, 20, 280, 360 ) mapa.x = display.contentCenterX mapa.y = display.contentCenterY mapa.mapType = "standard" mapa:setCenter(
setRegion
)无法使其工作
我尝试了以下方法:
一,
局部映射
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
二,。这个工作正常
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正确获取数字
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()
感谢您的帮助。一种解决方案是重复将位置硬件排队,直到收到正确的响应,然后调用此函数。有关详细信息,请参见中的示例。起初我认为它会起作用,因为它与我的第二次尝试相同,但有一个函数可以精确控制何时加载地图。我将用我编写的代码编辑我的帖子,尝试您的解决方案。是否可能在地图加载后需要超过2秒的时间来添加标记?我已经尝试了所有方法,只有在使用getUserLocation()作为添加pin的位置时,它才有效。它不适用于其他位置