【问题标题】:Getting really bad accuracy from CLLocationManager从 CLLocationManager 获得非常糟糕的准确性
【发布时间】:2017-06-26 01:01:17
【问题描述】:

我正在使用 CLLocationManager 来获取用户位置。

我想获得一个位置更新。

我的问题是我变得非常糟糕horizontalAccuracy

位置是 %@ +/- 3881.91m

垂直精度:65.4401861912846,水平精度:3881.90892434957

代码:

fileprivate lazy var locationManager: CLLocationManager = {
    let manager = CLLocationManager()
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.delegate = self
    manager.requestAlwaysAuthorization()
    manager.pausesLocationUpdatesAutomatically = false
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.distanceFilter = kCLDistanceFilterNone
    return manager
}()

override init() {
    super.init()
    locationManager.startUpdatingLocation()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let mostRecentLocation = locations.last else {
        return
    }
    
    let verticalAccuracy =  mostRecentLocation.verticalAccuracy
    let horizontalAccuracy = mostRecentLocation.horizontalAccuracy
    
    print("location is %@", mostRecentLocation)
    print("verticalAccuracy: \(verticalAccuracy), horizontalAccuracy:\(horizontalAccuracy)")
}

任何建议为什么会发生这种情况? 我在靠近窗户的房间里,所以我除了精度差,但还不错。

谢谢


我得到了荒谬的结果。

我的水平精度为 15,000 m。

当我出门时效果很好,但在门里不应该像这样糟糕。

使用蜂窝三角测量和 wifi 应该会产生更好的结果。


20 分钟后,我开始在门中获得 +- 50 m 精度的良好结果。

【问题讨论】:

  • 您在哪里测试应用程序?近窗不是一个好的选择。
  • @Apurv,为什么不呢?我不希望得到最好的结果,但 4 公里的精度是荒谬的。

标签: ios swift core-location cllocationmanager


【解决方案1】:

我一直发现,当你第一次开始位置更新时,最初的几个读数很差,然后随着 GPS 稳定下来,准确性会提高。

我要做的是首先检查该位置的时间戳是否超过几秒钟。如果是,我丢弃它。 (不确定最近的操作系统版本是否仍会发送“陈旧”的 GPS 读数,但系统会为您提供上次 GPS 启动时的位置,有时是几个 小时 之前的。)

获得当前位置后,我会检查准确性,并丢弃任何准确度读数太差的位置更新。只有当我得到足够好的读数时,我才会使用它(在你的情况下停止位置更新,因为你只想要 1 次更新。)

请记住,GPS 可能需要 30 秒(或更长时间)才能稳定下来,并且在 GPS 信号较差的区域,您可能永远无法获得足够好的读数。

【讨论】:

  • 我让该位置运行了 15 分钟,但仍然得到同样糟糕的结果
  • 你。不能在室内测试这个。您必须添加日志记录并在户外使用手机才能打开天空,没有高大的建筑物或树木阻挡 GPS 信号。
  • 我知道它的配偶在户外工作得更好,但结果是嘲笑,4 公里的准确度。在室内使用蜂窝/wifi 应该会产生更好的效果。
  • 如果您在金属框架建筑中,您可能根本看不到读数。
【解决方案2】:

我建议您添加一个条件,以确保您将使用更准确的位置。在我的情况下,我在下面的示例中使用 20 作为所需的水平精度。

例子:

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

         locationManager.stopUpdatingLocation()

         if locations.last!.horizontalAccuracy < 20 {
            //Only use location that enters here
         }
         else {
            //If the accuracy is not met then start updating location again and if possible increase more the accuracy (use kCLLocationAccuracyBestForNavigation if you really need it). Make sure that you use the desired accuracy and filter properly to avoid draining battery.
            locationManager.startUpdatingLocation()
         }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 2012-05-06
    • 2011-12-19
    • 2017-01-25
    • 2018-06-27
    • 2010-09-16
    • 2017-05-27
    相关资源
    最近更新 更多