Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager last known location

To get the last know geolocation, I have:

CLLocationManager * locationManager = [[CLLocationManager alloc] init];
CLLocation * lastKnownLocation = [locationManager location];

Does the lastKnownLocation reflect the last location my app has been called back with or does it reflect a global iOS system level last location (which other app or the iOS might have queried for)?

I am doing this instead of actively querying for user's location so I don't waste the user's battery.

If user has not given permission to access location, obviously lastKnownLocation should be nil. My question is specifically for the case where user has given my app permission to access location.

like image 244
mobileideafactory Avatar asked Mar 26 '14 23:03

mobileideafactory


2 Answers

Generally you should not simply rely on the existing (if any) value returned from location unless you check its accuracy and time stamp (compared to your requirements). It's better to start startUpdatingLocation until you get a location which does match your accuracy requirements and then either stopUpdatingLocation or switch to stopMonitoringSignificantLocationChanges (if available).

The location returned from location is very dependent upon history, so you can't definitely say one way or the other that it will be. You always need to verify the accuracy for your purposes.

like image 197
Wain Avatar answered Sep 28 '22 05:09

Wain


I know this is an old question but for the sake of being complete and maybe others ending up here:

The CLLocationManager class has the location property which returns (according to official Apple docs):

The most recently retrieved user location.

This method will return nil when no location is known.

like image 21
Maurits van Beusekom Avatar answered Sep 28 '22 06:09

Maurits van Beusekom