tags:

views:

216

answers:

1

I'm logging gps points during a walk. Below it shows the function that the coordinates are saved each 5 seconds. i Did several tests but i cannot get the right accuracy i want. (When testing the sky is clear also tests in google maps shows me that the gps signal is good).

here is the code:

-(void)viewDidAppear:(BOOL)animated{  

 if (self.locationManager == nil){

  self.locationManager = [[[CLLocationManager alloc] init] autorelease];
  locationManager.delegate = self;
  // only notify under 100 m accuracy
  locationManager.distanceFilter = 100.0f;
  locationManager.desiredAccuracy= kCLLocationAccuracyBest;
  [locationManager startUpdatingLocation];
 }
}

 - start logging

[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getData) userInfo:nil repeats:YES];
</code>

<code>
-(void)getData{

 int distance;

 // re-use location.
 if ([ [NSString stringWithFormat:@"%1.2f",previousLat] isEqualToString:@"0.00"]){
  // if previous location is not available, do nothing
  distance = 0;
 }else{
  CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:previousLat longitude:previousLong];
  CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:latGlobal longitude:longGlobal];

  distance = [loc1 getDistanceFrom: loc2];
 }

 // overwrite latGlobal with new variable 
 previousLat = latGlobal;
 previousLong = longGlobal;


 // store location and save data to database 
 // this part goes ok
}

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

 // track the time to get a new gps result (for gps indicator orb)
 lastPointTimestamp = [newLocation.timestamp copy];

 // test that the horizontal accuracy does not indicate an invalid measurement
     if (newLocation.horizontalAccuracy < 0) return;

 // test the age of the location measurement to determine if the measurement is cached
    // don't rely on cached measurements
     NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
     if (locationAge > 5.0) return;

 latGlobal = fabs(newLocation.coordinate.latitude);
 longGlobal= fabs(newLocation.coordinate.longitude); 
}

I have taken a screenshot of the plot results (the walk takes 30 minutes) and an example of what i'am trying to acomplish: http://www.flickr.com/photos/21258341@N07/4623969014/

i really hope someone can put me in the right direction.

+1  A: 

Looking at your plots - This is exactly what I see too in an app I am working on.

Looking at your code. Whenever location is updated, locationManager calls didUpdateToLocationFromLocation - polling at 5s intervals will give you a lot of points at the same location. (but not relevant to the question)

Also I think you are leaking a lastPointTimestamp (not relevant to the question)

Right - the jumping around - you can look at the accuracy of the points : you do this in locationManager anyway but only check for <0. Is there a pattern of what the horizontal accuracy is on the jumping points ? The accuracy figure may be much worse then for other points, or one specific value (caused by a switch to cell tower triangulation).

Finally, you may need to implement filtering. Kalman filters are the over-the-top way to go, but I am looking at using low-pass filters combined with some basic physics (max acceleration & speed for walking, cycling, running, driving etc) to improve results.

Happy to collaborate on this.

Andiih
Hi Andiih, Thanks for your suggestions. Maybe it's indeed better to work the other way around. Store the best 'didUpdateLocation' result based on accuracy and save with a maximum of 1 point per 5 seconds. Filtering, for example an max distance based on speed, does give cleaner results, but is one step ahead for me. i will post my findings and new code when i have tested. Thanks
Martijn
I spent some more time looking at this today. I noticed that the bad "jumppoint" (for you on the road) is always the same point. I wonder if you can filter on high relative speed and repeated visits to the same point.
Andiih
This is going to turn into a discussion. If you want to contact me over this please mail andrew dot hawken at fiftyeggs dot co dot uk - I'm making some progress but it would be good to share datasets etc as we work on it : SO is for questions and answers not discussions.
Andiih