Iphone 定位速度
我正在开发GPS应用程序。 你知道如何检测移动设备的速度吗 实际上,我需要每2秒检测一次速度 我知道当位置更改时会调用didUpdateToLocation方法Iphone 定位速度,iphone,objective-c,ios,performance,cllocation,Iphone,Objective C,Ios,Performance,Cllocation,我正在开发GPS应用程序。 你知道如何检测移动设备的速度吗 实际上,我需要每2秒检测一次速度 我知道当位置更改时会调用didUpdateToLocation方法 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 但我认为这种方法不适合我的问题
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
但我认为这种方法不适合我的问题
那么,我是否需要在2秒内检查[CLLocationManager location]
的速度
有什么建议吗
提前感谢。您只能真正使用您在问题中建议的委托方法 即使每2秒访问一次[CLLocationManager location],您也只会收到上次在上述委托方法中收到的坐标 为什么需要每两秒钟进行一次投票?在某些情况下,iphone可以在更短的时间内更新坐标
HTH下面的代码是如何从委托方法工作的。 或者,如果您确实想要轮询,则保留您以前的位置,并检查与上次轮询的距离变化,并使用手动方法(也显示在下面)计算速度 速度以m/s为单位计算/提供,因此,公里/小时乘以3.6或英里/小时乘以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被贬值。替换CLLocationDistanceChange=[newLocation getDistanceFrom:oldLocation];使用CLLocationDistanceChange=[newLocation distanceFromLocation:oldLocation];