Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Use and then turn off Geolocation services

iOS / Titanium 1.4.1.1

I have an app with the following:

Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 200;
Ti.Geolocation.getCurrentPosition(function(e) {
Ti.Geolocation.addEventListener('location', locationListener);
});

and a map somewhere…

mapView = Ti.Map.createView({
  mapType: Ti.Map.STANDARD_TYPE,
  userLocation:true,
  animate:true
});

and then finally, when the map is no longer needed, there is:

Ti.Geolocation.removeEventListener('location', locationListener);
mapView.hide();

Here's what I've observed…

  1. Once the location is used, iOS shows the purple location services indicator
  2. Even though the map is no longer displayed (I tried to remove it but get a crash), and I think the geoLocation eventListener has been removed, location services stays active
  3. If I switch to another app under iOS 4 multitasking, location services icon goes away; switching back usually turns it on, but not all the time; if it is off then I can navigate to the map tab and it goes on

Is there a way to stop requesting location services?

— asked October 11th 2010 by matt raj
  • geolocation
  • mapview
  • mobile
0 Comments

1 Answer

  • Accepted Answer

    The Objective-C that is created for the project (GeolocationModule.m around line 369) does have code to turn off location services if you remove all the listeners. From the looks of it you need to make sure the reference counts drop to 0 for both location and heading listeners or the location services will remain on.

    — answered October 11th 2010 by John McKnight
    permalink
    1 Comment
    • First, this is an excellent response, and it gave me a glimmer of hope. While I was adding and removing the event listener correctly, and your answer supports this, I hadn't noticed that the mapView had userLocation = true which caused the geoLocation services to be active even when the map was hidden. Anyhow, I set userLocation = false when it's not needed and the geoLocation services toggle just fine. Thanks!

      — commented October 11th 2010 by matt raj
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.