iOS CoreLocation检查CLLocation时间戳以使用它

你如何检查一个CLLocation对象,并决定是否要使用它,或放弃结果,并得到一个新的位置更新呢?

我看到CLLocation上的timestamp属性,但我不知道如何将它与当前时间进行比较。

另外,在比较了时间之后,我们可以发现秒之间的差异,那么使用该CLLocation对象的区别是什么? 什么是一个好的门槛。

谢谢!

检查时间戳是非常重要的,因为iOS通常会caching位置,并且作为第一个度量返回最后一次caching,所以下面是我在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 } } 

我用了30秒。 正如你所看到的,我也检查结果的一致性问横向的准确性。
希望这可以帮助,
安德里亚