سؤال

I'm developing a fitness tracking app like Runtastic, Nike+ etc. I'll be mapping the entire activity from start to finish. I don't start updating location changes when the app launches, instead I'm starting when the user starts a workout. But when the locationManager start updating, first 3 to 5 CLLocations are very incorrect. Up to a kilometer in errors. I'm using the following code to initialize the location manager:

self.locationManager = [(PFAppDelegate *)[[UIApplication sharedApplication] delegate] locationManager];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.locationManager.distanceFilter = 5.0;
[self.locationManager startUpdatingLocation];

And in the locationManagerDidUpdateToLocation method:

 if( didFindGPS == NO )
 {
     if( [[lastLocation timestamp] timeIntervalSinceNow] < 10.0 )
     {
         if( [lastLocation horizontalAccuracy] < 20)
         {
            didFindGPS = YES;
         }
     }
 }
 else
 {
     //process data here
 }

This doesn't filter out those first incorrect locations. I've also tried ignoring locations that have horizontalAccury values that are smaller than 20, but then the app doesn't process any locations.

What can be done to improve the first locations or to handle the first incorrect ones?

هل كانت مفيدة؟

المحلول

Change

if ([lastLocation horizontalAccuracy] < 20)...

to

if (([lastLocation horizontalAccuracy] > 0) && ([lastLocation horizontalAccuracy] < 20))...

According to documentation

A negative value indicates that the location’s latitude and longitude are invalid.

A negative value of horizontalAccuracy that is.

If you want to set the condition for processing data (seems like you do) you should rewrite the code to:

if (([lastLocation horizontalAccuracy] > 0) && ([lastLocation horizontalAccuracy] < 20))
{
    didFindGPS = YES;
    //process the data here... since here the location fits your limitations
    //and you don't loose the first location (as in original code)
}
else
{
    didFindGPS = NO;
}

Note that this code can give you some false alarms for loosing the GPS so you might want to omit the else block.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top