iphone - iOS: locationManager:didUpdateToLocation:fromLocation: 不移动时报告速度

标签 iphone ios gps core-location cllocationmanager

我正在使用 locationManager:didUpdateToLocation:fromLocation: 获取位置更新。大多数一切都运行良好,但是当我站着检查 newLocation.speed 属性时,我几乎总是得到一个大于 0 的速度值。即使我第一次开始获取位置更新并且从未移动过,我也会在之后获得正值一些更新。

只要做一个简单的大于 0 的检查然后设置一个 UILablel 如果它是:

if (newLocation.speed > 0) {
     self.speed.text = [NSString stringWithFormat:@"%.2f",[self speed:newLocation.speed]];
}

该方法的更多代码:

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

    // Check first if we are getting the accuracy we want
    if (newLocation.horizontalAccuracy < 0) return;

    // Make sure the update is new not cached
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) return;

    // Check to see if old and new are the same
    if ((oldLocation.coordinate.latitude == newLocation.coordinate.latitude) &&
        (oldLocation.coordinate.longitude == newLocation.coordinate.longitude)) return;

    // Make sure our new location is not super far away from old
    CLLocationDistance dist = [newLocation distanceFromLocation:oldLocation];
    NSLog(@"Distance: %f", dist);
    if (dist > 40) return;

    // Make sure we have a new location
    if (!newLocation) return;

    // Check to see if we are stopped
    if (newLocation.speed == 0) {
        self.inMotion = NO;
    } else if (newLocation.speed > 0) {
        self.inMotion = YES;
    } else {
        // Probably an invalid negative value
        self.inMotion = NO;
    }//end

    // Speed
    // Should always be updated even when not recording!
    if (newLocation.speed > 0 && inMotion) {
        self.speed.text = [NSString stringWithFormat:@"%.2f",[self speed:newLocation.speed]];
        NSLog(@"Speed: %f", newLocation.speed);
    }

    // Tons more code below that I removed for this post

}//end

这正常吗?

最佳答案

比零大多少?持续多长时间?您比较的所有位置的准确度是否相同?

在 GPS 接收器中,速度通常由连续定位之间的位置变化决定(也可以通过测量多普勒频移来计算)。由于测量误差或随着它们变得更加准确,位置修复会略有不同。位置的变化会使设备看起来像是移动了​​。

例如,假设您的第一个定位点的水平精度为 1000 米,而您的第二个定位点的水平精度为 300 米,那么第一个位置可能与实际位置相差 1000 米,而第二个位置可能与第一个定位点相距 700 米即使设备没有移动。这转化为位置随时间的变化,即“速度”。

关于iphone - iOS: locationManager:didUpdateToLocation:fromLocation: 不移动时报告速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7563271/

相关文章:

ios - 自构建预编译头以来文件已被修改

ios - 为什么 magnetic Field.field 的值固定为零?

iphone - 对于架构 i386 xcode 5,ld : symbol dyld_stub_binding_helper not found, 通常位于 crt1.o/dylib1.o/bundle1.o 中

iphone - UITableviewCell 中的 UILabel 动态高度行为不稳定

Android如何查看gps是否连接到卫星?

iphone - 使用不同 View 中 UICell 的内容更新 UILabel

ios - 如何在 Delphi 中使用 Indy HTTP Server 来接收 iOS 应用程序中的连接?

ios - 列出重新加载动画故障

ios - 检测 wifi 启用(无论是否连接)

JAVA - GPS 接收器在控制台中发送奇怪/编码的帧