ios - iPhone GPS 用户位置在手机静止时来回移动

标签 ios swift gps mapkit core-location

我正在做一些 mapkit 和 corelocation 编程,我在其中绘制用户路线。例如。他们去散步,它显示了他们走过的路。

在模拟器上一切正常 100%。

在 iPhone 上,我遇到了一个大问题,我不知道该怎么办。为了确定用户是否“停止”,我主要检查速度是否(几乎)为 0 一段时间。

然而,只要保持手机仍然吐出此日志以获取最新更新的位置更改(来自位置管理器委托(delegate))。这些是 locationManager(_:didUpdateLocations:) 回调中的连续更新。

speed 0.021408926025254 with distance 0.192791659974976
speed 0.0532131983839802 with distance 0.497739230237728
speed 11.9876451887096 with distance 15.4555990691609
speed 0.230133198005176 with distance 3.45235789063791
speed 0.0 with distance 0.0
speed 0.984378335092039 with distance 11.245049843458
speed 0.180509147029171 with distance 2.0615615724029
speed 0.429749086272364 with distance 4.91092459284206

现在我将精度设置为最佳:

_locationManager                    = CLLocationManager()
_locationManager.delegate           = self
_locationManager.distanceFilter     = kCLDistanceFilterNone
_locationManager.desiredAccuracy    = kCLLocationAccuracyBest

你知道是否有设置或者我可以更改以防止这种来回行为。当手机静止不动时,甚至用户图钉每隔几秒就会左右剧烈移动。

或者我还需要编写其他代码来解释这种狂妄自大的行为吗?

最佳答案

我检查用户是否在特定时间内移动了特定距离以确定他们是否已经停止(感谢 rmaddy 提供的信息):

/**
    Return true if user is stopped. Because GPS is in accurate user must pass a threshold distance to be considered stopped.
*/
private func userHasStopped() -> Bool
{
    // No stop checks yet so false and set new location
    if (_lastLocationForStopAnalysis == nil)
    {
        _lastLocationForStopAnalysis = _currentLocation
        return false
    }

    // If the distance is greater than the 'not stopped' threshold, set a new location
    if (_lastLocationForStopAnalysis.distanceFromLocation(_currentLocation) > 50)
    {
        _lastLocationForStopAnalysis = _currentLocation
        return false
    }

    // The user has been 'still' for long enough they are considered stopped
    if (_currentLocation.timestamp.timeIntervalSinceDate(_lastLocationForStopAnalysis.timestamp) > 180)
    {
        return true
    }

    // There hasn't been a timeout or a threshold pass to they haven't stopped yet
    return false
}

关于ios - iPhone GPS 用户位置在手机静止时来回移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957520/

相关文章:

ios - 使用图像在 objective-c 中创建 PDF 表单

iphone - UIGestureRecognizer在<OS3.2上崩溃

ios - UITableViewCell 无法将标签约束到右边缘

android - 如何获得当前职位的城市名称?

mysql 带有地理位置的大表 - 查找交集

ios - 在后台线程中向 UIScrollView 添加大量按钮 - 按钮不可见

ios - 自定义 UIView 标签和动画未显示在 View Controller 中

ios - Swift:设备锁定时继续播放声音

matlab - Lat/Lng 点到 Minor Arc 段的距离

ios - 如何像iOS照片应用程序一样实现缩放*和*分页