gpt4 book ai didi

iphone - C定位速度

转载 作者:技术小花猫 更新时间:2023-10-29 11:11:10 25 4
gpt4 key购买 nike

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

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

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

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

但是我觉得这个方法不适合我的问题。

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

有什么建议吗?

提前致谢。

最佳答案

下面的代码如何从委托(delegate)方法中工作。或者,如果您确实想要投票,则保留您之前的位置并检查距离上次投票的变化,并使用手动方法(如下所示)来计算速度。

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

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

}
}

关于iphone - C定位速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1391589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com