我正在开发GPS应用程序。你知道如何检测移动设备的速度吗?
实际上,我需要每2秒检测一次速度。
我知道当位置改变时会调用didUpdateToLocation方法。
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation但我认为这个方法不适合我的问题。
那么,我需要在2秒内检查[CLLocationManager location]的速度吗?
有什么建议吗?
提前谢谢。
发布于 2009-10-10 16:24:18
下面由委托方法工作的代码如何?或者,如果您想要轮询,那么保持原来的位置,检查与上次轮询的距离,并使用手动方法(也如下面所示)来计算速度。
速度是计算/提供的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;
}
}发布于 2009-10-02 11:33:17
您只能真正使用您在问题中建议的委托方法。
即使每隔2秒访问一次CLLocationManager位置,也只会收到上次在上述委托方法中收到的坐标。
为什么需要每两秒进行一次投票?在某些情况下,iphone可以在较短的时间内更新坐标。
HTH
https://stackoverflow.com/questions/1391589
复制相似问题