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_Coronasdk - Fatal编程技术网

Lua 正在尝试获取要在屏幕上显示的经度和纬度

Lua 正在尝试获取要在屏幕上显示的经度和纬度,lua,coronasdk,Lua,Coronasdk,我需要在屏幕上显示经度和纬度我已经看过corona SDK中的一些示例, 我只是还在挣扎 这就是我现在所拥有的,它只是每次都显示相同的坐标,而不是我现在所在的位置 local latitude = display.newText( "-", 100, 50, native.systemFont, 16 ) local longitude = display.newText( "-", 100, 100, native.systemFont, 16 ) local locationHandle

我需要在屏幕上显示经度和纬度我已经看过corona SDK中的一些示例, 我只是还在挣扎

这就是我现在所拥有的,它只是每次都显示相同的坐标,而不是我现在所在的位置

local latitude = display.newText( "-", 100, 50, native.systemFont, 16 )

local longitude = display.newText( "-", 100, 100, native.systemFont, 16 )

local locationHandler = function( event )

    if ( event.errorCode ) then
        native.showAlert( "GPS Location Error", event.errorMessage, {"OK"} )
        print( "Location error: " .. tostring( event.errorMessage ) )
    else
        local latitudeText = string.format( '%.4f', event.latitude )
        latitude.text = latitudeText

        local longitudeText = string.format( '%.4f', event.longitude )
        longitude.text = longitudeText
    end
end

-- Activate location listener
Runtime:addEventListener( "location", locationHandler )

你在模拟器上运行这个代码吗?甚至XCode模拟器?如果是这样,那就是为什么。。。模拟器会给你(上次我检查时)加州的某个地方作为默认设置(我不确定它是否可以更改),因为大多数笔记本电脑没有GPS装置

您需要在实际设备上运行代码,以正确测试位置代码。要做到这一点,最简单的方法是使用Corona Live,这使得更改代码和重新部署到多个设备非常容易,无需任何努力。

你说的什么意思,每次都显示相同的坐标?请在Youtube和文档中尝试。