用户通过CLLocationManager或GoogleMap-IOS跟踪的距离

时间:2014-08-04 12:40:38

标签: ios cllocationmanager google-maps-sdk-ios gmsmapview

我正在使用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的distanceFilter "财产或我能做些什么来计算更精确的旅行距离...?

1 个答案:

答案 0 :(得分:0)

这是因为您将所需的准确度设置为kCLLocationAccuracyBestForNavigation。只需删除该行。此外,标题的默认值设置为1,这是非常准确的。不要将其设置为kCLHeadingFilterNone

这将阻止定期更新,只有当您移动5米时才能获得。