在Corona SDK for Android中添加标记

我无法添加标记(仅在Android设备上尝试)。我想在地图加载后立即添加标记。通过添加延迟,已经使其工作,但无法通过仅添加标记或再次缩放地图(使用“setRegion”)使其工作。

我尝试了以下内容:

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(tonumber41.641208),tonumber-0.896030),{
    title =“El Rincon de la Encina”,
    subtitle =“Ofertas diarias!”})
mapa:setRegion(41.641208-0.8960300.010.01false)
mapa.isLocationVisible = true
  1. 这个可以正常工作
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: timereventmapa:addMarkertonumber(41.641208),tonumber(-0.896030),{
        title =“El Rincon de la Encina”,
        subtitle =“Ofertas diarias!”})
end

timer.performWithDelay(30000,listener

只有当计时器在加载地图后调用函数时,才能获得所需的结果。

添加“to number”的原因是确保Corona正确获取数字。

  1. @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()
    

感谢您的帮助。

点赞
用户4348158
用户4348158

一个解决方案是反复排队位置硬件,直到收到正确的响应,然后调用此函数。详见object:getUserLocation()中的示例。

2015-03-03 23:37:53