iPhone Geolocation doesn't work second time
I am writing an AR section for an iPhone app and the first time it runs it works great, but if I exit out of the screen (not the app) and then return to the AR screen the geolocation eventlistener that I add again does not ever get called.
Titanium.Geolocation.addEventListener('heading',goHeading);
I notice the same happens in KitchenSink in the AR demo screen, so it's not just me…
Someone had this problem with Android (http://developer.appcelerator.com/question/43171/android-titaniumgeolocation-wont-run-again-after-pressing-the-arrow-button) - is there a fix for the iPhone SKD as well?
6 Answers
-
I have the exact same problem with the location listener (among numerous other problems).
If I exit the page and go back again it never starts up. Leaving the app and going back in again, it starts up fine.
Did you ever sort this out?
-
Have you tried doing a Titanium.Geolocation.removeEventListener('heading'); when you 'close/blur' the window? Then start it when you 'open/focus' it?
-
Same problem here (iPhone) : my app shows the email dialog, and once closed, hop, no more heading. Even removing and setting back the event listener does not bring it to life.
-
Removing and resetting the listener works for me (SDK 1.7.2):
Ti.Geolocation.distanceFilter = 15; var locationCallback = function(e) { Ti.Geolocation.removeEventListener('location', locationCallback); Ti.Geolocation.addEventListener('location', locationCallback); hiApp.location = e.coords; } Ti.Geolocation.addEventListener('location', locationCallback);
-
The Problem still exists, anyone has found a workaround for that? Im' on 1.7.5 and 1.7.6.20111206
-
I've fixed it. If you remove the eventListener and there is no event listener registered, the framework stops working and you will never be able to register an event listener for location again. The only chance is to restart the app or program it the right way as appcelerator expects it:
var locationCallbackEnabled = false; var locationCallback = function(e) { Ti.API.info('coords: '+e.coords); } // If you register one, you have to remove one Ti.Geolocation.addEventListener('location', locationCallback); // save the information, that an event listener is registered locationCallbackEnabled = true; var removelocationCallback = function() { /* ATTENTION: This is the most important thing. * Check if the listener is added or not. * If you don't do this, you will not be able to * add an event listener again! */ if (locationCallbackEnabled) { Ti.Geolocation.removeEventListener('location', locationCallback); // save the information, that locationCallbackEnabled = false; } } // remove the event listener after 20 seconds setTimeout(removelocationCallback, 1000*20); // if you do this again, it is now save because // locationCallbackEnabled is set to false setTimeout(removelocationCallback, 1000*25);