Found this code via CODE EXCHANGE and it should do what i need. But for some reason it stopsafter a few runs. My skills are lacking so i cant figure why it stops. I need to get GPS position x seconds until i stop the app . Can anyone tell me why it stops ??
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()