Skip to content

Instantly share code, notes, and snippets.

@DoubleSlashDesign2
Last active August 29, 2015 14:17
Show Gist options
  • Save DoubleSlashDesign2/06696dde986f1db56d56 to your computer and use it in GitHub Desktop.
Save DoubleSlashDesign2/06696dde986f1db56d56 to your computer and use it in GitHub Desktop.
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