为什么我的CLLocation速度不准确? [英] Why is my CLLocation speed so inaccurate?

查看:99
本文介绍了为什么我的CLLocation速度不准确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用iPhone SDK玩了一下,我想在我的应用程序中显示当前的速度。有这么多的应用程序可以做到非常精确,特别是对于跑步或骑自行车等低速运动。我见过的最好的是RunKeeper。



但是,在我的应用程序中,速度绝对不准确。在低速时它总是空的,只有在更高的速度下它才会显示一些数值,但它们很少被更新并且没有什么用处。

   - (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
if(newLocation.timestamp> oldLocation.timestamp& amp; ;&
newLocation.verticalAccuracy> 0.0f&&& amp; // GPS是活动的
newLocation.horizo​​ntalAccuracy< 500.0f&&&& amp;&< GPS是活动的
// newLocation .horizo​​ntalAccuracy< kCLLocationAccuracyHundredMeters&& amp;& amp;& amp; //良好GPS质量信号
//newLocation.speed> 1.0f&&&& amp;&&& // //准确速度和航向测量的足够移动
oldLocation!= nil )// oldLocation是无读一读
{
double speed =(newLocation.speed * 3.6);
[self updateDisplayWithSpeed:speed];
// double direction = newLocation.course;




$ b $ p $有没有人有工作代码?或者你能告诉我什么是我的错?

解决方案

我会尝试以下操作。 b

请记住,您应根据您的情况设置distanceFilter和desiredAccuracy:步行与汽车旅行等不同。此外,当您从GPS请求高精度时,必须始终放弃GPS提供的第一个位置,并使用第二个位置作为起始位置。引用Apple文档:

您应该为此属性分配一个适合您的使用场景的值。换句话说,如果您只需要几公里内的当前位置,则不应指定kCLLocationAccuracyBest来确保准确性。以更高的准确度确定位置需要更多的时间和更多的权力。
当请求高准确度的位置数据时,位置服务提供的初始事件可能没有您请求的准确性。定位服务尽可能快地提供初始事件。然后,它会继续以您请求的准确度确定地点,并在必要时提供额外的事件,当数据可用时。



这是我的建议。

首先,使用GPS以至少一秒的时间间隔更新位置。低于此间隔时,速度值无用,因为它以米/秒为单位进行测量,并且由于前面的讨论,您不可能在不到一秒钟内获得有效更新且精度高。第二,只对位置坐标使用有意义的值:你应该丢弃具有负水平准确性的值。这就是我说的好的地点。



第三,你可以自己计算距离:计算上一个好位置和前一个好位置之间的距离位置使用getDistanceFrom(),然后除以位置更新之间经过的秒数。这会给你以米/秒为单位的距离。我会尽力做到这一点,并将结果与​​Apple提供的速度进行比较。


I´m playing a bit with the iPhone SDK and I want to show the current speed in my application. There are so many apps that can do that really precise, especially for low speeds like running or biking. The best I've seen is RunKeeper.

But, in my application, the speed is absolutely inaccurate. In low speeds it is always null, and only at higher speeds it shows some values but they are rarely updated and not really useful.

- (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;
    }
}

Does anyone have working code for that? Or can you tell me what´s wrong with mine?

解决方案

I would try the following.

Remember that you should set the distanceFilter and desiredAccuracy as needed by your scenario: walking is not the same as traveling by car etc. Moreover, when you request high accuracy from the GPS, you must always discard the very first location provided by the GPS and use the second one as the starting location. Quoting the Apple documentation:

You should assign a value to this property that is appropriate for your usage scenario. In other words, if you need only the current location within a few kilometers, you should not specify kCLLocationAccuracyBest for the accuracy. Determining a location with greater accuracy requires more time and more power. 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.

Here is my suggestion.

First, update the location using the GPS using an interval of at least one second. Below this interval the speed value is useless because it is measured in meters per second and owing to the previous discussion, you are not likely to get a valid update in less than a second with high accuracy.

Second, only use meaningful values for the location coordinates: you should discard values with negative horizontalAccuracy. This is what I am referring to when speaking of good locations.

Third, you can compute the distance by yourself: compute the distance between the last good location and the previous good location using getDistanceFrom() and then divide by the number of seconds elapsed between the location update. This will give you the distance in meters per second. I will try to do this and compare the result with the Apple provided speed.

这篇关于为什么我的CLLocation速度不准确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆