CLLocationManager提供错误的位置更新

时间:2015-02-20 12:49:41

标签: ios xcode gps cllocationmanager

我正在开发一个跟踪应用,需要在地图上显示跟踪路径。当我开始更新位置并且在安装后没有移动设备时,locationManagar会报告错误的位置更新,

enter image description here

我正根据报告的位置点绘制路线

此外,当用户在直路上高速驾驶车辆时,也显示出这样的故障,

如何忽略这些错误的位置更新

您可以下载应用here并自行测试

1 个答案:

答案 0 :(得分:0)

查看水平精度检查以确保您拥有准确的位置。例如,低于10米或低于零:

    // test that the horizontal accuracy does not indicate an invalid measurement
    if (lastLocation.horizontalAccuracy < 0)
        return;

并确保您有一个新位置,因为它将返回最后一个默认位置:

// test the age of the location measurement to determine if the measurement is cached
        // in most cases you will not want to rely on cached measurements
        NSTimeInterval locationAge = -[lastLocation.timestamp timeIntervalSinceNow];
        if (locationAge > 5.0)
            return;

还要确保在CLLocationManager上设置正确的desiredAccuracy。例如:

_manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
相关问题