0

I'm using MKMapView and I start the map at the last known location with CLLocationManager, the problem is that the iPhone and Location Services reports that I'm still using the services after I'm done which rises some concerns about battery usage.

So, please help me release this properly.

CLLocationManager * MANG = [[CLLocationManager alloc] init];
[MANG startMonitoringSignificantLocationChanges];
if(MANG.location){
   [mapa setCenterCoordinate:MANG.location.coordinate animated:NO];
}
[MANG stopMonitoringSignificantLocationChanges];
[MANG stopUpdatingLocation];
[MANG release];
Aravindhan
  • 15,608
  • 10
  • 56
  • 71
Diego Torres
  • 5,308
  • 5
  • 25
  • 29
  • Two things... 1) Are you sure that you are still using the location service? Normally you call stop in one of the delegate methods once you received a notification that you have a location or the change that you are looking for. Right now you are not waiting long enough between start and stop. 2) Are you calling [map setShowsUserLocation:YES] or map.showsUserLocation = YES anywhere in your code? If so, this will continue to enable the location service until you set the value to no. – sho Oct 24 '11 at 20:56
  • I just need to retrieve the lastest known location (don't care if is new) to initialize the map at that point, that's why i'm using it that way. After that, yes, I'm using map. showsUserLocation but I set it to NO when I'm no longer using it. – Diego Torres Oct 24 '11 at 21:08
  • Do you have the show my location checked for your mapview? That will supersede any calls to the location manager showing you are tracking location. – Bill Burgess Oct 27 '11 at 18:30

1 Answers1

0

There are two ways to fetch the location using Location Services: the first one, less accurate but more battery friendly; and the second one more accurate.

When you declare [myLocationManager startMonitoringSignificantLocationChanges] your iPhone checks for location every time you left a cell tower and enter into a new one. When you declare [myLocationManager startUpdatingLocation] your iPhone checks for location every time the GPS detects a position change (maybe each 1-3 meters, depending on accuracy).

So the thing is, in your code you’re trying to stop the declared Location Manager twice. Just remove the second stop instruction and you’ll get the correct code:

CLLocationManager * MANG = [[CLLocationManager alloc] init];
[MANG startMonitoringSignificantLocationChanges];
if(MANG.location){
   [mapa setCenterCoordinate:MANG.location.coordinate animated:NO];
}
[MANG stopMonitoringSignificantLocationChanges];
[MANG release];
Jorge Ramos
  • 891
  • 10
  • 21