Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

GPS location location not working if change scene composer
Started by fixr Mar 27 2018 06:00 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

fixr

[GLOBAL: userInfoPane.html]
fixr
  • Observer

  • 4 posts
  • Corona SDK

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
 
 

 

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,102 posts
  • Corona Staff

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



[TOPIC: post.html]
#3

fixr

[GLOBAL: userInfoPane.html]
fixr
  • Observer

  • 4 posts
  • Corona SDK

Thank you Rob!
It works! I moved the listener to main.lua


[TOPIC: post.html]
#4

fixr

[GLOBAL: userInfoPane.html]
fixr
  • Observer

  • 4 posts
  • Corona SDK

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).


[TOPIC: post.html]
#5

fixr

[GLOBAL: userInfoPane.html]
fixr
  • Observer

  • 4 posts
  • Corona SDK

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?




[topic_controls]
[/topic_controls]