【问题标题】:Adding markers in Corona SDK for Android在 Corona SDK for Android 中添加标记
【发布时间】: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 得到正确的号码。

  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()
    

感谢您的帮助。

【问题讨论】:

    标签: android google-maps lua coronasdk marker


    【解决方案1】:

    一种解决方案是重复对定位硬件进行排队,直到它收到正确的响应,然后调用此函数。有关详细信息,请参阅object:getUserLocation() 中的示例。

    【讨论】:

    • 起初我认为它会起作用,因为它与我的第二次尝试相同,但具有精确控制地图加载时间的功能。我将使用我在尝试您的解决方案时编写的代码来编辑我的帖子。加载地图后添加标记是否可能需要超过 2 秒的时间?
    • 我什么都试过了,只有当我使用 getUserLocation() 作为添加 pin 的位置时它才有效。它不适用于其他位置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 2012-12-31
    • 1970-01-01
    相关资源
    最近更新 更多