This sends “or should send” a users location every 15 seconds. Everything is firing correctly except it is sending the same location until the app is closed and re-opened. If you fully exit the app and come back the location will be correct one time.
How to reset the location or pull the current location without having to exit the app
local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local json = require ("json") local decodedData local muserID = system.getInfo( "deviceID" ) local reXlistener = {} local gotolocation = {} local latitude = display.newText( "", -100, -100, native.systemFont, 1 ) local longitude = display.newText( "-", -100, -100, native.systemFont, 1 ) local altitude = display.newText( "", -100, -100, native.systemFont, 1 ) local accuracy = display.newText( "", -100, -100, native.systemFont, 1 ) local speed = display.newText( "", -100, -100, native.systemFont, 1 ) local direction = display.newText( "", -100, -100, native.systemFont, 1 ) local time = display.newText( "", -100, -100, native.systemFont, 1 ) local timesTwoRun = 10 system.setIdleTimer( false ) function scene:create( event ) local sceneGroup = self.view background = display.newImageRect( "images/bg.png", 318, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert( background ) logoBtn = display.newImageRect("images/rexlogo.png", 260, 198) logoBtn.x = centerX -4 logoBtn.y = 115 sceneGroup:insert(logoBtn) local highlight = display.newImage ("images/highlight.png",480,644) highlight.x = display.contentWidth /2+300 highlight.y = display.contentHeight/2 highlight.alpha = 0.4 highlight.rotation = -75 transition.to(highlight, {delay=1200, alpha=0.0,xScale=10.0, yScale=32.0, x=90, time=2200}) -------------------------------------------- local function gotoCancel( self, event ) if event.phase == "began" then timer.cancel(rexTimer) timer.cancel(rexPanic) composer.gotoScene( "home", "crossFade", 800 ) return true end end completeBtn = display.newImageRect("images/panic-cancel.png", 200, 223) completeBtn.x = centerX completeBtn.y = 338 completeBtn.alpha = 0 sceneGroup:insert(completeBtn) completeBtn.touch = gotoCancel completeBtn:addEventListener( "touch", completeBtn ) local function makeREXConnections( event ) if ( event.isError ) then print( "Network error!") else myNewData = event.response local tninja = json.decode( event.response ) for key in pairs(tninja) do local server\_connected = tninja[key]["server\_connected"] -- currentThis = tonumber(server\_connected) transition.to( completeBtn, { delay=10, effect = "fade", time=3300, alpha=9} ) end end end local function gotoREX( event ) network.request( "http://www.domain.com/checkin.php?f=hw&rex\_type=2&onlyrunonce=1&u\_device="..muserID.."&xsaccuracy=".. accuracy.text .."&xsspeed=".. speed.text .."&xslat=".. latitude.text .."&xslog=".. longitude.text, "GET", makeREXConnections ) end --local gotolocation = function( event ) local function gotolocation( event ) if ( event.errorCode ) then native.showAlert( "GPS Location Error", event.errorMessage, {"OK"} ) print( "Location error: " .. tostring( event.errorMessage ) ) else native.showAlert( "GPS Location ", event.latitude, {"OK"} ) latitudeText = string.format( '%.4f', event.latitude ) latitude.text = latitudeText longitudeText = string.format( '%.4f', event.longitude ) longitude.text = longitudeText accuracyText = string.format( '%.3f', event.accuracy ) accuracy.text = accuracyText speedText = string.format( '%.3f', event.speed ) speed.text = speedText timeText = string.format( '%.0f', event.time ) time.text = timeText print(latitude.text) print(time.text) gotoREX() Runtime:removeEventListener( "location", gotolocation) end end function reXlistener:timer( event ) Runtime:addEventListener( "location", gotolocation) end end function scene:show( event ) local phase = event.phase if "did" == phase then rexTimer = timer.performWithDelay( 1000, reXlistener, 1 ) rexPanic = timer.performWithDelay( 15000, reXlistener, timesTwoRun ) end if "will" == phase then transition.to( completeBtn, { delay=1, effect = "fade", time=1, alpha=0} ) end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end function scene:destroy( event ) local sceneGroup = self.view transition.to( completeBtn, { delay=1, effect = "fade", time=1, alpha=0} ) composer.removeScene( "checkin", false ) end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene