【问题标题】:Location listener Corona sdk位置监听器 Corona sdk
【发布时间】:2016-12-31 15:16:23
【问题描述】:

我正在使用 Corona SDK 处理基于位置的应用程序。 我有图像和图像角值(Lat - Long)。使用下面的代码查找 XY 像素。但是位置侦听器无法正常工作。在 android 位置侦听器在第一次执行后触发。我每 1 米得到准确的经纬度值。

 local function GetPixelCoordinatesInBounds( width,height,lat,lon )

    minLat = 12.9837
    maxLat = 12.9850
    MAP_HEIGHT = W
    minLon = 80.24662
    maxLon = 80.24666
    MAP_WIDTH = H-35

    x = ((lon - minLon) / (maxLon - minLon)) * (MAP_WIDTH - 1)
    y = ((lat - minLat) / (maxLat - minLat)) * (MAP_HEIGHT - 1)
end

local function locationHandler(event)
 if ( event.errorCode ) then
         native.showAlert( "GPS Location Error", event.errorMessage, {"OK"} )

 else
    GetPixelCoordinatesInBounds(ImageWidth, ImageHeight,  event.latitude, event.longitude)
 end
   Runtime:addEventListener( "location", locationHandler ) 

【问题讨论】:

  • 你能补充更多细节吗?即听者。
  • 那么,当你的意思是监听器不工作时,它不准确吗?还是 GPS 功能本身不起作用?
  • 没有得到准确的值。在同一个地方我得到了差异值。

标签: lua gps geolocation coronasdk


【解决方案1】:

我认为您没有正确处理坐标。看看这个坐标转换的例子,应用程序工作正常:

function locationHandler(event)
        -- Check for error (user may have turned off Location Services)
    if event.errorCode then
        title = display.newText( "errorgps", 200, 150, "Verdana-Bold", 20 )
        --print( "Location error: " .. tostring( event.errorMessage ) )
    else

         ycor = string.format( '%.6f', event.latitude )
         xcor = string.format( '%.6f', event.longitude )
         accuracyText = string.format( '%.3f', event.accuracy )
    end

mxl0 = 5
 myl0 = 4
-- Specifically check here how you have to manipulate your local y coordinates 
        mxl = ((mxl0-xmin)/(xmax-xmin))*300+10
        myl = -((myl0-ymin)/(ymax-ymin))*300+460
            if mylocationi == 1 then mxl = ((mxl-zx[1])/(zx[2]-zx[1]))*300 end
        if mylocationi == 1 then myl = ((myl-(zy[1]+zy[2])/2)/(zx[2]-zx[1]))*300+160 end
    if mxl > 340 then mxl = 340 end
    if myl > 460 then myl = 460 end
    if mxl < 0 then mxl = 5 end
    if myl < 160 then myl = 160 end


     mylocation = display.newCircle( mxl, myl, 3 )
     mylocation:setFillColor( 0,0,1 )
     timer.performWithDelay( 1000, removecircle )

end
Runtime:addEventListener( "location", locationHandler )

检查这个应用程序,如果这是你想要做的,我可以给你代码: https://play.google.com/store/apps/details?id=com.jorc.amirfarazmand.GPS&hl=en

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多