问题
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];
回答1:
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];
来源:https://stackoverflow.com/questions/7881743/cllocationmanager-not-stopping-releasing