GPS location location not working if change scene composer

Hi,

when I use Runtime:addEventListener( “location”, locationHandler ) in composer scene (example SCENE1.lua) working well and show event.latitude and event.longitute.

But when I change the scene (example SCENE2.lua)  and return to previous scene (SCENE1.lua, when the addEventListener working) the addEventListener not restart and not show the gps parameters.

I use the example of gps location in Corona Apis.

Could do you help me?

Thank you

Welcome to the forums!

I would either suggest either adding the listener in main.lua if you’re going to need it in multiple scenes, or if you just need it in one scene, make sure to remove the listener when you leave that scene so you’re not stacking up listeners.

Keep in mind that it takes time to sync up with the GPS system and it’s a pretty expensive operation for your app, so starting it up early and leaving it running seems to be more practical that turning it on and off frequently.

Rob

Thank you Rob!

It works! I moved the listener to main.lua

Hi, I write in this post because I have a another problem.

The listener is to main.lua, and when I open the app (Android and Ios) the system show a popup for activate gps.

But if the user have a gps globally off in the S.O. settings?

There is a method for verify this settings?

Because the app not working and not show message or error (only with adb with nil values).

local locationHandlerGps = 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 latitudeText = string.format( '%.4f', event.latitude ) print("LATITUDINE "..latitudeText) longitudeText = string.format( '%.4f', event.longitude ) print("LONGITUDINE "..longitudeText) accuracyText = string.format( '%.3f', event.accuracy ) end end -- THIS LISTENER NOT START IF GPS IT'S OFF? Runtime:addEventListener( "location", locationHandlerGps )

THE LISTENER NOT START IF GPS IT’S OFF?

Welcome to the forums!

I would either suggest either adding the listener in main.lua if you’re going to need it in multiple scenes, or if you just need it in one scene, make sure to remove the listener when you leave that scene so you’re not stacking up listeners.

Keep in mind that it takes time to sync up with the GPS system and it’s a pretty expensive operation for your app, so starting it up early and leaving it running seems to be more practical that turning it on and off frequently.

Rob

Thank you Rob!

It works! I moved the listener to main.lua

Hi, I write in this post because I have a another problem.

The listener is to main.lua, and when I open the app (Android and Ios) the system show a popup for activate gps.

But if the user have a gps globally off in the S.O. settings?

There is a method for verify this settings?

Because the app not working and not show message or error (only with adb with nil values).

local locationHandlerGps = 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 latitudeText = string.format( '%.4f', event.latitude ) print("LATITUDINE "..latitudeText) longitudeText = string.format( '%.4f', event.longitude ) print("LONGITUDINE "..longitudeText) accuracyText = string.format( '%.3f', event.accuracy ) end end -- THIS LISTENER NOT START IF GPS IT'S OFF? Runtime:addEventListener( "location", locationHandlerGps )

THE LISTENER NOT START IF GPS IT’S OFF?