ios - 位置管理器为旧位置提供新时间戳

标签 ios cllocationmanager cllocation

我的 iPhone 应用程序出现以下问题:

我会定期启用位置管理器,并且会等待多个位置更新。当接收到新位置时,我检查新位置的时间戳属性以了解它是否是旧位置:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {

    numberOfUpdatesInInterval++;
    NSLog(@"%d;%f;%f;%.0f;%@;%@;%@",
                              numberOfUpdatesInInterval,
                              newLocation.coordinate.latitude,
                              newLocation.coordinate.longitude,
                              newLocation.horizontalAccuracy,
                              newLocation.timestamp,
                              [self getCurrentDateAsString],
                              newLocation);
}

我现在遇到的问题是我收到了时间戳是新的新位置,但坐标仍然是我之前收到的旧位置。当我以 120 公里/小时的速度驾驶我的汽车时,我对此进行了测试,多次收到相同的坐标但时间戳不同。我在 iOS 4 和 5 中遇到了同样的问题。

这怎么可能?或者我该如何处理这个问题?

最佳答案

iPhone 有几种获取其位置的方法。

  • 细胞信号
  • wifi 接入点
  • GPS 卫星

最快的位置查找是小区信号定位。只要您最近有数据,大多数本地塔都会被缓存。手机信号塔精度范围从 500 米到 1500 米或更远。

如果您有数据连接或最近去过该地区,第二快的是 wifi 查找。这将提供一个非常准确的位置。需要注意的是,您必须在 wifi 附近并拥有良好的数据信号。

最慢的是 GPS。 iPhone 中的 GPS 是 aGPS。它使用来自手机信号塔位置的数据来更好地定位您的位置。如果手机没有数据连接并且不在 wifi 附近,则可能需要 2 到 4 分钟才能修复。使用手机信号塔信息可能需要 30 秒。

来自苹果文档:

When requesting high-accuracy location data, the initial event delivered by the location service may not have the accuracy you requested. The location service delivers the initial event as quickly as possible. It then continues to determine the location with the accuracy you requested and delivers additional events, as necessary, when that data is available.

在汽车中,您不太可能靠近 wifi 位置,并且可能需要等待更长的时间才能锁定 GPS。如果 locationManager 认为您仍在先前位置的范围内,这可能会导致具有不同时间戳的旧坐标。

检查数据的 horizo​​ntalAccuracy 以及时间戳以确定位置是否与您要求的一样准确。

关于ios - 位置管理器为旧位置提供新时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8041693/

相关文章:

ios - 需要获得超过 20 个区域监控通知

ios - 如何使用请求警报自定义位置服务

ios - 计算行程时间 CLLocation Swift

ios - 如何获取按钮相对于 super View 的坐标?

ios - iOS 上的 Google Play 游戏服务出错

ios - Xcode 未在正确的子目录中搜索 header

ios - LocationManager 坐标为零

ios - 在 iOS 上编写异步 Web 服务调用的最佳实践

ios - 在 viewDidLoad 中获取位置

objective-c - NSPredicate 与 FUNCTION 不起作用