【问题标题】:Swift iOS, CLLocationManager didUpdateLocations recording unvisited locationsSwift iOS,CLLocationManager didUpdateLocations 记录未访问的位置
【发布时间】:2017-06-04 04:30:48
【问题描述】:

在我用 Swift 3 在 XCode8 for iOS 上编写的 GPS 应用程序中,CLLocationManager didUpdateLocations 被调用得很好,但我发现它经常接受我没有访问过的位置(在 iOS 9 中测试)

下面是我设置的带有相关记录位置的 MKMapView 的图片

http://imgur.com/eLYUAqy

  • 红点 = 起点(向北行驶)

  • 蓝点 = 完成(沿着我向北行驶的相同路径返回后)

  • 绿点 = 从来没有去过这么远的南方

注意:我在录制这段视频时正在开车,而不是在跑步。不确定这是否重要

所以在回家的路上,我从红点附近转向蓝点所在的房子,我从不向南走。 我想知道当我没有向南走这么远的时候,为什么 CLLocationManager 记录器位置在绿点(我已经多次记录了这条路径并且这种情况一直在发生,也许是假设我正在到达 70m 外的十字路口?)

我正在绘制我的行驶距离与持续时间和速度与行驶距离的关系图,所以我也看到了这些结束时的尖峰,因为在很短的时间内我转身进入我的房子,CLLocationManager 假设我已经搬到了十字路口底部的绿点,然后又回来,包括了所有的距离。

我已尝试更改 distanceFilter 和 Horizo​​ntalAccuracy 但这并没有解决问题。根据我在网上阅读的内容,我猜我可能需要以某种方式平滑我的数据或过滤掉不切实际的加速度,但我不确定我将如何实现这一点。

下面是我的 CLLocationManager 的相关代码。任何有关如何解决此问题的帮助都会很棒,谢谢!

var distance = 0.0
@IBOutlet weak var mapView: MKMapView!



lazy var locationManager: CLLocationManager = {
    var _locationManager = CLLocationManager()
    _locationManager.delegate = self
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest
    _locationManager.activityType = .fitness
    _locationManager.distanceFilter = 10.0
    return _locationManager}()
lazy var locations = [CLLocation]()



extension GPSTracker: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    for location in locations {
        let howRecent = location.timestamp.timeIntervalSinceNow
        let accuracy = location.horizontalAccuracy
        if abs(howRecent) < 10 && accuracy < 10 && accuracy > 0 && location.verticalAccuracy > 0 {
            let region = MKCoordinateRegionMakeWithDistance(location.coordinate, 500, 500)
            mapView.setRegion(region, animated: true)
            if self.locations.count > 0 {
                    distance += location.distance(from: self.locations.last!)
                    var coords = [CLLocationCoordinate2D]()
                    coords.append(self.locations.last!.coordinate)
                    coords.append(location.coordinate)
                    mapView.add(MKPolyline(coordinates: &coords, count: coords.count))}
            self.locations.append(location)}}}

【问题讨论】:

    标签: ios swift cllocationmanager


    【解决方案1】:

    说白了,iOS GPS 是松鼠式的。它有时会给出虚假读数。您必须教您的应用过滤掉不良读数。

    您应该在每次获取位置更新时检查“水平精度”读数。这是一个“混乱半径”值,以米为单位。 真实位置可以在具有该半径的圆内的任何位置。因此,如果值为 500,则表示您的真实位置可能在半径为 500 米的圆圈内的任何位置,也可能是周长为一公里的圆圈内的任何位置。

    当卫星信号变弱时,GPS 读数的质量会下降(奇怪的是,较大的“水平精度”值意味着 GPS 读数更差。)您需要确定对不良 GPS 信号的容忍度,并拒绝读数比你的承受能力差。此时,您应该向用户显示“GPS 信号弱”消息。

    【讨论】:

    • 感谢您的回复 Duncan,我再次跟踪了此驱动器上的水平精度,并且我一直在接受 0 到 10m 之间的任何值,这是否意味着它应该是准确的 +/- 10m 半径?有趣的是,十字路口的绿点距离 80m(从谷歌地图)
    猜你喜欢
    • 2023-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多