Vin*_*ngh 6 real-time cllocationmanager ios
如何计算设备上的实时速度?我已经google了很多,但我得到的只是在完成旅程后计算距离和速度.我可以在运行时计算速度吗?
建议将不胜感激.
提前致谢.
这里的CLLocationManager类提供不同的位置字段,如纬度、经度、精度和速度。
我用CoreLocationController它来进行位置更新,我称之为以下方法,您可以在- (void)locationUpdate:(CLLocation *)location 方法中获取当前速度,如下所示
- (void)locationUpdate:(CLLocation *)location
{
NSString *currentspeed = [NSString stringWithFormat:@"SPEED: %f", [location speed]];
}
Run Code Online (Sandbox Code Playgroud)
或者下面是委托方法
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"in update to location");
NSString *currentspeed = [NSString stringWithFormat:@"SPEED: %f", [newLocation speed]];
}
Run Code Online (Sandbox Code Playgroud)
您也可以从此链接获取示例... http://www.vellios.com/2010/08/16/core-location-gps-tutorial/
我希望这对你有帮助...:)