问题
How do you check a CLLocation object and decide whether you want to use it or discard the result and get a new location update instead?
I saw the timestamp property on CLLocation, but I'm not sure how to compare that to the current time.
Also, after I do compare the time and find the difference in seconds, what value should the difference be under for me to use that CLLocation object? What's a good threshold.
Thanks!
回答1:
Is really important to check the timestamp, because iOS usually caches the location and as a first measure returns the last cached, so here is how I do inside the delegate method of Core Location Manager:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation * newLocation = [locations lastObject];
//check if coordinates are consistent
if (newLocation.horizontalAccuracy < 0) {
return;
}
NSTimeInterval interval = [newLocation.timestamp timeIntervalSinceNow];
//check against absolute value of the interval
if (abs(interval)<30) {
//DO STUFF
}
}
I use 30 seconds.
As you can see I also check the consistency of the result asking the horizontal accuracy.
Hope this helps,
Andrea
来源:https://stackoverflow.com/questions/14119303/ios-corelocation-checking-cllocation-timestamp-to-use-it