我正在使用 GoogleMap-IOS-1.8.1 SDK 来显示地图。我必须计算用户走过的步行距离。搜索后我会尝试使用CLLocationManager的方法 -
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
double new_travelled_distance = [newLocation distanceFromLocation:oldLocation];
total_distanceTravelled_by_user += new_travelled_distance; }
并像这样初始化-
-(void)viewDidLoad{
[super viewDidLoad];
if(!locationManager)
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:5.0f]; // measured in meters
[locationManager setHeadingFilter:kCLHeadingFilterNone]; // measured in degrees
[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
}
[locationManager startUpdatingLocation]; }
但这并不能提供准确的数据,即使我坐在同一个地方也没有走一米,但它可以让我定期更新以改变位置。我是否必须更正“ CLLocationManager's distanceFilter ”属性或者我可以做些什么来更准确地计算行进距离......?