Reputation: 1890
For android phone, you can retrieve the last available location point regardless of whether your current location service is on or not, which is quite helpful as you could make a guess based on that before the most up-to-date location is available.
How could I do that for iPhone? Assuming when I try to access iOS location service, the user already walks indoor. As a result, the most up-to-date location is not available. Is it possible for me to retrieve the location the last time the user is exposed under the sky?
Thanks!
Upvotes: 1
Views: 278
Reputation: 3940
I don't know if there is an out-of-box method you can use directly. but in my app, i used a work around. i simply saved the most recent user location into the NSUserDefault like this
- (void)setLastSavedLocation:(CLLocation *)location
{
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.latitude forKey:@"kLocationManagerLatKey"];
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.longitude forKey:@"kLocationManagerLngKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
and i would call this to get the data:
- (CLLocation *)lastSavedLocation
{
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"kLocationManagerLatKey"]) return nil;
return [[CLLocation alloc] initWithLatitude:[[NSUserDefaults standardUserDefaults] doubleForKey:@"kLocationManagerLatKey"]
longitude:[[NSUserDefaults standardUserDefaults] doubleForKey:@"kLocationManagerLngKey"]];
}
Hope that would give you some ideas to solve this problem.
Upvotes: 2