iOS CoreLocation检查CLLocation时间戳以使用它 [英] iOS CoreLocation checking CLLocation timestamp to use it

查看:219
本文介绍了iOS CoreLocation检查CLLocation时间戳以使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查CLLocation对象并决定是否要使用它或丢弃结果并获取新的位置更新?

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?

我看到了timestamp属性关于CLLocation,但我不确定如何将其与当前时间进行比较。

I saw the timestamp property on CLLocation, but I'm not sure how to compare that to the current time.

此外,在我比较时间并找出差异的秒数之后,我应该使用该CLLocation对象的差异是什么值?什么是好的门槛。

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.

谢谢!

推荐答案

非常重要检查时间戳,因为iOS通常会缓存该位置,并且作为第一个度量返回最后一个缓存,所以这里是我在Core Location Manager的委托方法中的方式:

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
        }
    }

我使用30秒。
如你所见,我也检查结果的一致性,询问水平精度。

希望这有帮助,
Andrea

I use 30 seconds. As you can see I also check the consistency of the result asking the horizontal accuracy.
Hope this helps,
Andrea

这篇关于iOS CoreLocation检查CLLocation时间戳以使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆