-->

iOS的CoreLocation检查CLLocation时间戳使用它(iOS CoreLocatio

2019-08-05 06:55发布

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

我看到CLLocation timestamp属性,但我不知道如何来比较当前的时间。

另外,以后我做比较时,发现在几秒钟​​的差别,应该区别是下我使用CLLocation对象什么价值? 什么是一个很好的阈值。

谢谢!

Answer 1:

是非常重要的检查时间戳,因为iOS的通常缓存位置,并作为第一指标返回最后缓存,所以这里是我的核心位置管理的委托方法里面怎么办:

- (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秒。 正如你可以看到我还检查结果,要求水平精度的一致性。
希望这可以帮助,
安德里亚



文章来源: iOS CoreLocation checking CLLocation timestamp to use it