I am working on map application,
I am try to use [locationManager stopUpdatingLocation];
method to stop the Location services.
It seems that it works fine in iOS4.3 but in iOS5, it's not working.
Please any one suggest me How to stop location services in iOS5?
Sometimes it happens that location manager does not stop even after stopUpdationLocations
.
You need to release your location manager, for that set:
locationManager = nil;
This should be written after:
[locationManager stopUpdatingLocation];
Also, take care you don't call locationManager object, after setting it to nil, else your application will crash.
If it stills not stopping location services, then there is work around solution, just use BOOL variable if you don't want to use it in future.
You may get help from below two links:
LINK-1:
http://iphonedevsdk.com/forum/iphone-sdk-development/2299-cllocationmanager-stopupdatinglocation-not-working.html
Refer to site_reg's answer in above link:
I was having the same problem, and it seems to be fixed by declaring a static BOOL in your .m file and checking it when you enter the didUpdateToLocation method.
@implementation MyFile
@synthesize MySynth;
static BOOL haveAlreadyReceivedCoordinates = NO;
Then in your didUpdateToLocation method:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if(haveAlreadyReceivedCoordinates) {
return;
}
haveAlreadyReceivedCoordinates = YES;
...
}
This won't technically make it stop receiving updates, but it will ignore any updates after the first one. If your app depends on getting just one location update to do its work, this should help.
EDIT-1:
Also once this is done, you can add locationManager.delegate = nil;
after [locationManager stopUpdatingLocation];
line.
LINK-2:
why self.locationManager stopUpdatingLocation doesn't stop location update
Refer to jnic's answer in above link:
The opposite of
startMonitoringSignificantLocationChanges
is notstopUpdatingLocation
, it isstopMonitoringSignificantLocationChanges
.You probably want to replace
startMonitoringSignificantLocationChanges
withstartUpdatingLocation
for the sake of more regular updates, unless you have a specific reason for monitoring only for significant location changes.Check out the CLLocation documentation for further detail.
I have added the answers from the link just to make sure that answer is useful even if the provided links goes down in future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With