我开发GPS应用。 你知道如何检测移动设备的速度?
其实,我需要检测速度每2秒。
我知道didUpdateToLocation
当位置改变方法被调用。
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
但我认为这种方法是不适合我的问题。
所以,我需要检查的速度[CLLocationManager location]
在2秒内?
任何建议?
提前致谢。
怎么样,低于该从委托方法工作的代码。 另外,如果你是想查询,则保留原来的位置,并检查从上次轮询改变的距离,并使用手工方法(如下所示)来计算速度。
速度计算/在米提供/太乘以3.6 KMPH或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;
}
}
你真的只能使用你已经在你的问题建议的委托方法。
即使你访问[CLLocationManager位置]每2秒,则只会收到您在上面的委托方法最后收到的坐标。
为什么需要每两秒钟轮询? 而iPhone更新坐标在某些情况下,更短的时间。
HTH