Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StopUpdatingLocation method not working for iOS5

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?

like image 701
Anki Avatar asked Dec 02 '22 20:12

Anki


2 Answers

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.

like image 125
P.J Avatar answered Dec 20 '22 22:12

P.J


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 not stopUpdatingLocation, it is stopMonitoringSignificantLocationChanges.

You probably want to replace startMonitoringSignificantLocationChanges with startUpdatingLocation 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.

like image 28
Parth Bhatt Avatar answered Dec 20 '22 22:12

Parth Bhatt