2

I am using GoogleMap-IOS-1.8.1 SDK for showing map. I have to calculate walking distance travelled by user. After searching i will try to use CLLocationManager's method -

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

double new_travelled_distance = [newLocation distanceFromLocation:oldLocation];
total_distanceTravelled_by_user += new_travelled_distance;  }

and initialising like this-

-(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];   }

But this doesn't provide data with accuracy, even i am sitting on same place not travelled a single meter but it give me regularly update for changing location. Should i have to correct " CLLocationManager's distanceFilter " property or what can i do for calculating more accurately travelling distance...?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gaurav Pandey
  • 1,953
  • 3
  • 23
  • 37
  • Location Manager will update everytime, even if you are sitting idle, but the difference will be oldlocation and newlocation data if you move, else both will be same, so your calculation in locationmanager delegate function should be on check if oldlocaion!=newlocation. – iphonic Aug 04 '14 at 12:54
  • ok i can also check in didUpdateToLocation method if distance difference is more than DistanceFilter, only than i will add. But this method is only called if distance difference is not less than than DistanceFilter. But my main problem is its fluctuation which many time come more than DistanceFilter (= 5 meter). – Gaurav Pandey Aug 04 '14 at 13:16
  • is it solved ? i am too having this problem here ! – dip Jan 22 '16 at 04:08

1 Answers1

0

It is because you are setting the desired accuracy as kCLLocationAccuracyBestForNavigation. Just remove that line. Also the default value of heading is set to 1 which is quite accurate. Do not set it to kCLHeadingFilterNone.

This will prevent the periodic updates and you will get it only when you will move by 5 meters.

Apurv
  • 17,116
  • 8
  • 51
  • 67
  • Not helping yet, I want highest possible accuracy and less conflict with distanceFilter property thats why i use kCLLocationAccuracyBestForNavigation. On removing "kCLLocationAccuracyBestForNavigation" or using kCLLocationAccuracyBest i am getting more fluctuation form my distance without walking any step. – Gaurav Pandey Aug 05 '14 at 07:49