OGeek|极客世界-中国程序员成长平台

标题: ios - ios中的位置时间戳准确性 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 23:44
标题: ios - ios中的位置时间戳准确性

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

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

下图取 self 的控制台日志。这里我使用了格式“Lat Long : latitude_longitude | location_timestamp | Now : current_timestamp

highlighted rows have older timestamps



Best Answer-推荐答案


是的,有时 ios 会以最准确的方式从缓存中获取位置,因此您需要避免该位置,此处是准确定位的代码。

更新: “由于返回初始位置可能需要几秒钟,因此位置管理器通常会立即提供先前缓存的位置数据,然后在可用时提供更多最新位置数据。因此,检查采取任何行动之前任何位置对象的时间戳。”

引用:

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

注意:您可以根据 ipod 和 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 - ios中的位置时间戳准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606592/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4