iOS中的位置时间戳准确度 [英] Location timestamp accuracy in ios

查看:161
本文介绍了iOS中的位置时间戳准确度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 10中分析了位置服务后,发现缓存行为存在一些不一致之处。



定期获取位置(以我为例,每20秒)会返回位置,但它们的时间戳未按时间顺序排列。这表明缓存位置可能有问题。因此,如果您要通过位置时间戳检查准确性,则最好也保存以前的时间戳。这样您就可以决定是否可以使用获取的位置。



以下图片是从我的控制台日志中获取的。在这里,我使用的格式为纬度:纬度 | 位置时间戳 |现在:当前时间戳



解决方案

是的,在某些情况下,最好的ios精度是

更新:
因为它是从高速缓存中定位的位置,因此您需要避免该位置。可能需要花费几秒钟的时间才能返回初始位置,因此位置管理器通常会立即提供以前缓存的位置数据,然后在可用时再提供更多最新的位置数据,因此检查任何位置的时间戳始终是一个好主意位置对象,然后再执行任何操作。



参考:



https://developer.apple.com/reference/corelocation/cllocationmanager



注意:您可以更改ipod和ipad等设备的准确性

  // MARK:位置代理
func locationManager(_管理器:CLLocationManager,didUpdateLocations位置:[CLLocation])
{
如果locations.count> 0
{
let location = location [locations.count-1]

let maxAge:TimeInterval = 60;
let requiredAccuracy:CLLocationAccuracy = 100;

让locationIsValid:Bool = Date()。timeIntervalSince(location.timestamp)< maxAge&& location.horizo​​ntalAccuracy< = requiredAccuracy;
if locationIsValid
{
NSLog( ,, location:%@,location);
NSLog(有效位置.....);

}
}
}


After analysing location services in iOS 10, found that some inconsistency is in the caching behaviour.

Fetching locations in a periodic time (in my case every 20 secs) returns locations but their timestamps are not in chronologically ordered. This indicates that the caching locations might have issues. So if you are checking accuracy through location-timestamp better to save the previous timestamps also. So that you could decide that the location fetched can be used or not.

Below image is taken from my console log. Here I used the format "Lat Long : latitude_longitude | location_timestamp | Now : current_timestamp"

解决方案

Yes some time in best accuracy ios take the location from the cache so you need to avoid that location here is the code for accurate locationtion.

Update : "Because it can take several seconds to return an initial location, the location manager typically delivers the previously cached location data immediately and then delivers more up-to-date location data as it becomes available. Therefore it is always a good idea to check the timestamp of any location object before taking any actions."

Reference :

https://developer.apple.com/reference/corelocation/cllocationmanager

Note: you can vary the accuracy for the device like ipod and ipad

//MARK: Location delgates
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
    {
        if locations.count > 0
        {
            let location = locations[locations.count-1]

            let maxAge:TimeInterval = 60;
            let requiredAccuracy:CLLocationAccuracy = 100;

            let locationIsValid:Bool = Date().timeIntervalSince(location.timestamp) < maxAge && location.horizontalAccuracy <= requiredAccuracy;
            if locationIsValid
            {
                NSLog(",,, location : %@",location);
                NSLog("valid locations.....");

            }
        }
    }

这篇关于iOS中的位置时间戳准确度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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