首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有没有办法在GPS给出的位置上获得更高的精度?

有没有办法在GPS给出的位置上获得更高的精度?
EN

Stack Overflow用户
提问于 2018-09-20 09:31:57
回答 1查看 439关注 0票数 1

我正在为IOS制作一个具有持久性对象的AR应用程序。然后,我在AR场景中放置的每个对象都与GPS位置一起存储。问题是:准确性。我使用的是swift的核心定位工具包,但在室内我无法获得低于4-6的精度(距离正确位置4-6米的误差)。然后在重新加载场景时,所有内容都会转移到其他地方。

我已经在用了

locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation

我试图得到几个样本来做加权平均,但我注意到在一些样本之后,获得的位置是相同的(精度也是4-6)。可能是斯威夫特自己做的。

我是不是漏掉了什么?一种获得更好方法的数学方法?还是没有更好的办法?

编辑

地点的速度如何?我应该更相信那些速度更快的人,还是说它根本不相关?

EN

回答 1

Stack Overflow用户

发布于 2018-09-20 12:36:12

我尝试了以下方法来跳过冗余的位置更新触发器。这种方法包括在您的UserDefaults中保存最新的位置更新。并且下一次接收到位置更新时,在将该位置接受为有效位置更新之前进行一系列检查,例如位置准确性、更新的时间戳、距离等。希望这能有所帮助。

代码语言:javascript
运行
复制
func setCurrentLocation(location: CLLocation) {

    let encodedLocation = NSKeyedArchiver.archivedData(withRootObject: location)
    UserDefaults.standard.set(encodedLocation, forKey: UserDefaultKey.previousVisitedLocation)
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    guard locations.count > 0 else {
        return
    }

    guard let location = locations.last else {
        return
    }

    guard location.horizontalAccuracy > 0 else {
        return
    }

    guard location.horizontalAccuracy < DISTANCE_LIMIT else { //DISTANCE_LIMIT is the value you have set for your distance filter
        return
    }

    let previousLocationEncoded = UserDefaults.standard.object(forKey: UserDefaultKey.previousVisitedLocation) as? Data

    if previousLocationEncoded == nil {

        setCurrentLocation(location: location)

        //do your tasks

    } else {

        let previousLocationDecoded = NSKeyedUnarchiver.unarchiveObject(with: previousLocationEncoded!) as! CLLocation

        let distanceBetweenVisits = previousLocationDecoded.distance(from: location)

        if distanceBetweenVisits > DISTANCE_LIMIT {

            let timeIntervalBetweenVisits = location.timestamp.timeIntervalSince(previousLocationDecoded.timestamp)

            guard timeIntervalBetweenVisits > 0 else {
                return
            }

            setCurrentLocation(location: location)

            //do your tasks
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52416273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档