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.
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.
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.
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