StopUpdatingLocation method not working for iOS5

前端 未结 2 825
南笙
南笙 2021-01-06 03:37

I am working on map application,

I am try to use [locationManager stopUpdatingLocation]; method to stop the Location services.

It seems that it

相关标签:
2条回答
  • 2021-01-06 03:52

    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.

    0 讨论(0)
  • 2021-01-06 04:01

    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.

    0 讨论(0)
提交回复
热议问题