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.
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.
上一篇: 困惑于iOS约束的方向