为什么我的CLLocation速度如此不准确?(Why is my CLLocation speed

2019-06-26 18:16发布

I'm打了一下,与iPhone SDK和我想表明我的应用程序的当前速度。 有这么多的应用程序,可以做到这一点真的很精确,尤其是在低速像跑步或骑自行车。 我见过的最好的是RunKeeper。

但是,在我的应用程序,速度是绝对不正确的。 在低速时它总是空的,只有在更高的速度下它显示了一些值,但他们很少更新,而不是真正有用。

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation {
    if (newLocation.timestamp > oldLocation.timestamp &&
        newLocation.verticalAccuracy > 0.0f &&                                  // GPS is active
        newLocation.horizontalAccuracy < 500.0f &&                                  // GPS is active
        //newLocation.horizontalAccuracy < kCLLocationAccuracyHundredMeters &&  // good quality GPS signal
        //newLocation.speed > 1.0f &&                                           // enough movment for accurate speed and course measurement
        oldLocation != nil)                                                     // oldLocation is nil on the first reading
    {
        double speed = (newLocation.speed * 3.6);
        [self updateDisplayWithSpeed:speed];
        //double direction = newLocation.course;
    }
}

有没有人有那个工作代码? 或者你可以告诉我what's错我的吗?

Answer 1:

我想尝试以下。

请记住,你应该设置distanceFilter和desiredAccuracy根据需要由情景:走路是不一样的自驾游等。此外,当你从GPS要求精度高,你必须抛弃通过GPS提供的第一个位置,使用第二个作为起始位置。 引述苹果文档:

你应该赋值给此属性是适合您的使用场景。 换句话说,如果你只需要几公里内的当前位置,你不应该的准确性指定kCLLocationAccuracyBest。 确定位置更加精确,需要更多的时间和更多的权力。 当要求高精确度的位置数据,通过位置服务交付的初始事件可能没有您所要求的精度。 位置服务尽快提供初始事件成为可能。 然后,它继续以确定与您所要求的精确度的位置,并提供必要的额外的事件,当这些数据是可用的。

这是我的建议。

首先,更新用使用至少一个秒的间隔的GPS位置。 低于这个区间,因为它是在每秒由于前面的讨论米测得的速度值是没用的,你不可能在不到一秒的高精度得到有效更新。

其次,只对位置坐标使用有意义的价值观:你应该抛弃值负horizo​​ntalAccuracy。 这就是我所说的好位置发言时。

第三,你可以自己计算距离:计算最后的好位置,并使用getDistanceFrom(),然后通过的位置更新之间经过的秒数除以前面的好位置之间的距离。 这会给你的距离在米每秒。 我会尽力做到这一点,与苹果公司提供的速度比较的结果。



Answer 2:

请尝试在您的代码如下:

speedLabel.text = [NSString stringWithFormat:@"SPEED(Km/Hr): %f", [location speed]*3.6];
latitudeLabel.text = [NSString stringWithFormat:@"LATITUDE: %f", location.coordinate.latitude];
longitudeLabel.text = [NSString stringWithFormat:@"LONGITUDE: %f", location.coordinate.longitude];
CLLocationDistance meters = [location distanceFromLocation:orginalLoc];
distanceLabel.text = [NSString stringWithFormat:@"DISTANCE(M): %f", meters];


文章来源: Why is my CLLocation speed so inaccurate?