Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 位置侦听器_Lua_Gps_Geolocation_Coronasdk - Fatal编程技术网

Lua 位置侦听器

Lua 位置侦听器,lua,gps,geolocation,coronasdk,Lua,Gps,Geolocation,Coronasdk,我正在使用Corona SDK处理基于位置的应用程序。 我有图像和图像角点值(Lat-Long)。使用下面的代码查找XY像素。但位置监听器工作不正常。在android中,位置监听器在第一次执行后激发。我每1米就有准确的纬度值 local function GetPixelCoordinatesInBounds( width,height,lat,lon ) minLat = 12.9837 maxLat = 12.9850 MAP_HEIGHT = W min

我正在使用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 ) 

我认为你没有正确处理坐标。看看这个例子,坐标被转换,应用程序运行良好:

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 )
函数位置处理程序(事件)
--检查错误(用户可能已关闭位置服务)
如果是event.errorCode,则
title=display.newText(“errorgps”,200150,“Verdana Bold”,20)
--打印(“位置错误:…tostring(event.errorMessage))
其他的
ycor=string.format('%.6f',event.latitude)
xcor=string.format('%.6f',event.longitude)
accuracyText=string.format('%.3f',event.accurity)
结束
mxl0=5
myl0=4
--在这里特别检查如何操作本地y坐标
mxl=((mxl0-xmin)/(xmax-xmin))*300+10
myl=-((myl0-ymin)/(ymax-ymin))*300+460
如果mylocationi==1,那么mxl=((mxl zx[1])/(zx[2]-zx[1])*300结束
如果mylocationi==1,那么myl=((myl-(zy[1]+zy[2])/2)/(zx[2]-zx[1])*300+160结束
如果mxl>340,则mxl=340结束
如果myl>460,则myl=460结束
如果mxl<0,则mxl=5结束
如果myl<160,则myl=160结束
mylocation=display.newCircle(mxl,myl,3)
mylocation:setFillColor(0,0,1)
定时器。延时性能(1000,移除循环)
结束
运行时:addEventListener(“位置”,locationHandler)
检查此应用程序,如果它是您尝试执行的操作,我可以为您提供代码:

您可以添加更多详细信息吗?i、 那么,当你的意思是听众没有工作时,这是不准确的?或者gps功能本身不起作用?我没有得到准确的值。在同一个地方我得到的是差值。