Hi Brent,
this is what I use at the very end of my main.lua file:
[lua]
---------------------------------------------------------------------------------------------------------------------------------------
– Add GPS related event listeners
---------------------------------------------------------------------------------------------------------------------------------------
Runtime:addEventListener( “location”, GPSSignalStrength )
Runtime:addEventListener( “location”, GPSlocationHandler )
Runtime:addEventListener( “heading”, GPSheadingHandler )
---------------------------------------------------------------------------------------------------------------------------------------
– require storyboard
local storyboard = require “storyboard”
– load first scene
storyboard.gotoScene(“mainscreen”)
[/lua]
The functions GPSSignalStrength(), GPSlocationHandler() and GPSheadingHandler() are sitting in a separate lua.file which I am requiring prior to adding the event listeners.
My GPSlocationHandler() function then tries to evaluate the longitude and latitude data:
[lua]
function GPSlocationHandler (event)
– Check for error (user may have turned off Location Services)
if event.errorCode then
– display error message
--print("GPS Location Error: "… tostring( event.errorMessage ))
– reset GPS signal counter
appData.totalSignals = 0
appData.GPSacquired = false
else
appData.totalSignals = appData.totalSignals + 1
if appData.totalSignals < 2 then appData.GPSacquired = false return end
– retrieve latitude / longitude information
_G.currentLatitude = tonumber(string.format( ‘%.4f’, event.latitude ))
_G.currentLongitude = tonumber(string.format( ‘%.4f’, event.longitude ))
…
…
…
[/lua]
Is the issue that I am initialising two “location” event listeners whereas Corona / the device can only handle one of these at a time (either GPSSignalStrength or GPSlocationHandler) but not both?
Jens