Método de services de location de iOS para Filtrar ubicaciones no válidas / inexactas

Estoy usando Location Services en algunas de mis aplicaciones. Tengo un método que uso en my locationManager:didUpdateToLocation:fromLocation: método para filtrar ubicaciones malas, inexactas o demasiado alejadas. Y para minimizar los gps "jitter". Aquí es lo que uso:

 /** * Check if we have a valid location * * @version $Revision: 0.1 */ + (BOOL)isValidLocation:(CLLocation *)newLocation withOldLocation:(CLLocation *)oldLocation { // Filter out nil locations if (!newLocation) return NO; // Filter out points by invalid accuracy if (newLocation.horizontalAccuracy < 0) return NO; if (newLocation.horizontalAccuracy > 66) return NO; // Filter out points by invalid accuracy #if !TARGET_IPHONE_SIMULATOR if (newLocation.verticalAccuracy < 0) return NO; #endif // Filter out points that are out of order NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp]; if (secondsSinceLastPoint < 0) return NO; // Make sure the update is new not cached NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow]; if (locationAge > 5.0) return NO; // Check to see if old and new are the same if ((oldLocation.coordinate.latitude == newLocation.coordinate.latitude) && (oldLocation.coordinate.longitude == newLocation.coordinate.longitude)) return NO; return YES; }//end 

¿Alguien tiene alguna mejora en este método para hacerlo más preciso? ¿Es 66 demasiado alto de horizontalAccuracy y recibirá muchas ubicaciones no válidas? ¿Debo bajar esto?

¿Hay alguna forma de get el "jitter" que los gps en el iPhone ofrecen?

Además de esto, hay otro que uso:

 if(self.lastKnownLocation) { CLLocationDistance dist = [newLocation distanceFromLocation:self.lastKnownLocation]; if(dist > newLocation.horizontalAccuracy) { //..... } } 

Donde self.lastKnownLocation es en realidad la última location válida que tengo y es una:

 @property(nonatomic, copy) CLLocation *lastKnownLocation; 
 -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (!newLocation) { NSLog(@"Filter out points by invalid accuracy"); return; } // Filter out points by invalid accuracy if (newLocation.horizontalAccuracy < 0) { return; } if(oldLocation.coordinate.latitude>90 && oldLocation.coordinate.latitude<-90 && oldLocation.coordinate.longitude>180 && oldLocation.coordinate.longitude<-180) { NSLog(@"old"); return; } if(newLocation.coordinate.latitude>90 || newLocation.coordinate.latitude<-90 || newLocation.coordinate.longitude>180 || newLocation.coordinate.longitude<-180) { NSLog(@"new"); return; } /////// NSDate *eventDate=newLocation.timestamp; NSTimeInterval eventinterval=[eventDate timeIntervalSinceNow]; if (abs(eventinterval)<30.0) { if (newLocation.horizontalAccuracy>=0 && newLocation.horizontalAccuracy<20) { **//finally you are getting right updated value here....** } } } 

Puedes pagar esto

https://medium.com/@mizutori/make-it-even-better-than-nike-how-to-filter-locations-tracking-highly-accurate-location-in-774be045f8d6

La idea principal es archivar los datos en el método didUpdateLocation:

El método de filter es así:

 func filterAndAddLocation(_ location: CLLocation) -> Bool{ let age = -location.timestamp.timeIntervalSinceNow if age > 10{ return false } if location.horizontalAccuracy < 0{ return false } if location.horizontalAccuracy > 100{ return false } locationDataArray.append(location) return true }