CL定位速度

Posted

技术标签:

【中文标题】CL定位速度【英文标题】:CLLocation speed 【发布时间】:2009-09-08 01:52:03 【问题描述】:

我正在开发 GPS 应用程序。 你知道如何检测移动设备的速度吗?

实际上,我需要每 2 秒检测一次速度。

我知道 didUpdateToLocation 方法是在位置更改时调用的。

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

但我认为这种方法不适合我的问题。

那么,我需要在 2 秒内检查 [CLLocationManager location] 的速度吗?

有什么建议吗?

提前致谢。

【问题讨论】:

【参考方案1】:

下面的代码如何使用委托方法。 或者,如果您确实想轮询,请保留您之前的位置并检查与上次轮询的距离并使用手动方法(如下所示)来计算速度。

速度以 m/s 为单位计算/提供,因此 kmph 乘以 3.6 或 mph 乘以 2.23693629。

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

   //simply get the speed provided by the phone from newLocation
    double gpsSpeed = newLocation.speed;

    // alternative manual method
    if(oldLocation != nil)
    
        CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
        NSTimeInterval sinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
        double calculatedSpeed = distanceChange / sinceLastUpdate;

       

【讨论】:

出于兴趣(就准确性而言)这两个选项中哪个更好? getDistanceFrom 已折旧。替换 CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation]; with CLLocationDistance distanceChange = [newLocation distanceFromLocation:oldLocation];【参考方案2】:

您只能真正使用您在问题中建议的委托方法。

即使你每 2 秒访问一次 [CLLocationManager 位置],你也只会收到你上次在上面的委托方法中收到的坐标。

为什么需要每两秒轮询一次?在某些情况下,iphone 可以在更短的时间内更新它的坐标。

HTH

【讨论】:

以上是关于CL定位速度的主要内容,如果未能解决你的问题,请参考以下文章

iOS干货? 定位

定位速度降低时播放音频播放器

Excel函数相对定位与绝对定位

Excel函数相对定位与绝对定位

Python + Selenium网页元素定位id 定位

Android GPS定位速度不可靠