I normally do not post on forums, but I was stuggling with this issue as well. I’ve spend hours on it already >.<
I have done a test in the simulator to update its GPS more than just once, looked promising, but I still have to test it on my Android. Each time you press the button its GPS gets updated.
Anyway:
Try using this technic http://docs.coronalabs.com/api/type/EventListener/addEventListener.html
with gettings it longtitude http://docs.coronalabs.com/api/event/location/longitude.html
I’ve read on the internet that you should not update its GPS too often, it might drain your battery.
I’ll give you a start:
–
– main.lua
local locationHandler = function( event )
– Check for error (user may have turned off Location Services)
if event.errorCode then
native.showAlert( “GPS Location Error”, event.errorMessage, {“OK”} )
print( "Location error: " … tostring( event.errorMessage ) )
else
print(‘GPS location update’)
end
end
– Events
local addListener1, addListener2 – forward references
– create a large button
local rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
rect:setFillColor( 128, 64, 64 )
– state1
function state1Cb( event )
print(“state1”)
Runtime:removeEventListener( “location”, locationHandler )
Runtime:addEventListener( “location”, locationHandler )
rect:removeEventListener( “tap”, state1Cb )
timer.performWithDelay( 1, addListener2 ) – ** Do this instead
return true
end
– state2
function state2Cb( event )
print(“state2”)
Runtime:removeEventListener( “location”, locationHandler )
Runtime:addEventListener( “location”, locationHandler )
rect:removeEventListener( “tap”, state2Cb )
timer.performWithDelay( 1, addListener1 ) – ** Do this instead
return true
end
function addListener2( )
rect:addEventListener( “tap”, state2Cb )
end
function addListener1()
rect:addEventListener( “tap”, state1Cb )
end
– start
addListener1() – add first listener