iPhone Gps logging inaccurate

Posted by Martijn on Stack Overflow See other posts from Stack Overflow or by Martijn
Published on 2010-05-20T09:04:55Z Indexed on 2010/05/20 9:30 UTC
Read the original article Hit count: 243

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk