Last active
August 29, 2015 14:17
-
-
Save DoubleSlashDesign2/06696dde986f1db56d56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local currentLatitude = 0 | |
local currentLongitude = 0 | |
local updateGps = 5000 -- update Gps every X seconds | |
local locationHandler = function( event ) | |
-- On update, stop listening to GPS signal to avoid battery draining | |
Runtime:removeEventListener( "location", locationHandler ) | |
-- Check for error (user may have turned off Location Services) | |
if event.errorCode then | |
print( "Location error: " .. tostring( event.errorMessage ) ) | |
else | |
currentLatitude = string.format( '%.4f', event.latitude ) | |
currentLongitude = string.format( '%.4f', event.longitude ) | |
print('current latitude: ' .. currentLatitude) | |
print('current longitude: ' .. currentLongitude) | |
end | |
end | |
local function updateGPSTimer() | |
-- Reload GPS location | |
Runtime:addEventListener( "location", locationHandler ) | |
-- Update again | |
timer.performWithDelay( 5000, updateGPSTimer ) | |
end | |
-- Start GPS timer | |
updateGPSTimer() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment