Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop updating location once I get current location?

I'm using Parse and with geoPointForCurrentLocationInBackground I can stop updating once a location is received without having to manually stop it.

How do I stop updating location immediately right after I receive location using CLLocationManager?

Edit

I know [self.locationManager stopUpdatingLocation]; stops it. What I'm really asking is, how do I know I've received location for the first time then stop it immediately?

like image 826
durazno Avatar asked Dec 07 '25 16:12

durazno


2 Answers

After getting your location, use this method:

[self.locationManager stopUpdatingLocation];
self.locationManager = nil;
like image 66
Vishnuvardhan Avatar answered Dec 09 '25 04:12

Vishnuvardhan


Call stopUpdatingLocation as soon as your didUpdateLocations method is called.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    [manager stopUpdatingLocation];
    //store your location
    self.location = [locations lastObject];
}
like image 39
Josh Heald Avatar answered Dec 09 '25 05:12

Josh Heald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!