Ios 从CLLocationManager获得非常差的准确性

Ios 从CLLocationManager获得非常差的准确性,ios,swift,core-location,cllocationmanager,Ios,Swift,Core Location,Cllocationmanager,我正在使用CLLocationManager获取用户位置 我想得到一个单一的位置更新 我的问题是我的水平精度越来越差了 位置为%@+/-3881.91米 垂直精度:65.4401861912846,水平精度:3881.90892434957 代码: 有什么建议说明为什么会发生这种情况吗? 我在一个靠窗的房间里,所以我想得到很差的准确度,但不是那么差 谢谢 我得到了荒谬的结果 我得到了15000米的水平精度 当我出门时,它工作得很好,但在门里不应该像这样糟糕 使用蜂窝三角测量和wifi应该会得到

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

我想得到一个单一的位置更新

我的问题是我的水平精度越来越差了

位置为%@+/-3881.91米

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

代码:

有什么建议说明为什么会发生这种情况吗? 我在一个靠窗的房间里,所以我想得到很差的准确度,但不是那么差

谢谢


我得到了荒谬的结果

我得到了15000米的水平精度

当我出门时,它工作得很好,但在门里不应该像这样糟糕

使用蜂窝三角测量和wifi应该会得到更好的结果



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

我总是发现,当您第一次开始位置更新时,最初的几个读数非常差,然后随着GPS的稳定,精度会提高

我要做的是首先检查位置上的时间戳是否超过几秒钟。如果是,我就丢弃它。(不确定最新版本的操作系统是否仍发送“过时”的GPS读数,但该系统用于提供上次GPS通电时的位置,有时是几个小时以前的位置。)

一旦我得到了当前位置,我会检查准确度,如果准确度读数太低,我会放弃任何位置更新。只有当我得到足够好的读数时,我才使用它(在你的情况下停止位置更新,因为你只需要一次更新。)


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

我建议您添加一个条件,以确保您只使用精度较高的位置。在我的例子中,我使用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()
         }
    }
func locationManager(manager:CLLocationManager,didUpdateLocations位置:[CLLocation]){
locationManager.StopUpdatengLocation()
如果位置。上次!。水平精度<20{
//仅使用此处输入的位置
}
否则{
//如果不满足精度要求,则再次开始更新位置,如果可能,请进一步提高精度(如果确实需要,请使用kCLLocationAccuracyBestForNavigation)。确保使用所需的精度并正确过滤,以避免耗尽电池电量。
locationManager.startUpdatingLocation()
}
}

我让该位置运行了15分钟,但仍然得到与您相同的坏结果。不能在室内测试。你必须加上日志记录,在没有高楼或树木阻挡GPS信号的情况下,把手机带到户外打开天空。我知道它的配偶在户外工作得更好,但结果是可笑的,精确到4公里。在室内使用手机/wifi应该可以获得更好的效果。如果你在一栋金属框架建筑中,你可能根本看不到任何读数。你在哪里测试该应用程序?“靠近窗口”不是一个好选项。@Apurv,为什么不呢?我并不期望得到最好的结果,但4km的准确度是荒谬的。
    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()
         }
    }