CLLocationManager y problemas de precisión - ¿alguna experiencia?


Así que estoy tratando con algunos problemas de precisión con el iPhone GPS. Tengo una aplicación que utiliza la ubicación.

En el método delegado locationManager: didUpdateToLocation: fromLocation: se me devuelve una ubicación. A partir de un poco de investigación, parece que el GPS no siempre es preciso en el primer resultado que devuelve, incluso cuando se establece la propiedad desiredAccuracy a kCLLocationAccuracyBest.

Para evitar esto, no llamo stopUpdatingLocation antes de que se devuelva newLocation: al menos 3 veces (esto es muy rápido). También he jugado con otros dos "requisitos" para si stopUpdatingLocation y devolver el newLocation. Una forma que intenté fue comprobar el lat y long para newLocation y comparar con oldLocation y si estos no eran idénticos, a continuación, mantener la actualización de la ubicación en ejecución. También traté de comprobar la distancia entre el oldLocation y newLocation y si es menos de 20 metros, está bien. Ambos se prueban con el retorno de al menos 3 carreras. La última forma es menos "estricta", ya que newLocation y oldLocation es bastante difícil salirse con la suya siendo 100% idénticos si el el usuario está en un vehículo en movimiento.

Ahora, mi problema es, que incluso al hacer lo anterior (básicamente no aceptar una ubicación, hasta que se hayan producido algunas actualizaciones en CLLocationManager Y comprobar la distancia entre los CLLocations (o si son idénticos) Todavía estoy viendo resultados algo extraños para las ubicaciones a veces, al probar.

Sería correcciones a veces si dejo la aplicación, ir a Mapas.aplicación, utilizar el GPS, a continuación, abrir multitarea, forzar salir de mi aplicación y luego volver a abrirla para obtener una limpia lanzar.

¿Alguna experiencia y posibles soluciones que la gente haya utilizado para sortear el mismo tipo de problema? Comments and solutions appreciated:)

Author: runmad, 2011-01-08

2 answers

No recuerdo de qué proyecto fue exactamente de donde obtuve el siguiente código, pero esto me ha funcionado muy bien (recuerdo que fue de un video de WWDC 2010). En mi código, dejé los comentarios del proyecto original en tacto, así que espero que esto ayude.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    // test the age of the location measurement to determine if the measurement is cached
    // in most cases you will not want to rely on cached measurements
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];

    if (locationAge > 5.0) return;

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

    // test the measurement to see if it is more accurate than the previous measurement
    if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
        // store the location as the "best effort"
        self.bestEffortAtLocation = newLocation;

        // test the measurement to see if it meets the desired accuracy
        //
        // IMPORTANT!!! kCLLocationAccuracyBest should not be used for comparison with location coordinate or altitidue 
        // accuracy because it is a negative value. Instead, compare against some predetermined "real" measure of 
        // acceptable accuracy, or depend on the timeout to stop updating. This sample depends on the timeout.
        //
        if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
            // we have a measurement that meets our requirements, so we can stop updating the location
            // 
            // IMPORTANT!!! Minimize power usage by stopping the location manager as soon as possible.
            //
            [self stopUpdatingLocation:NSLocalizedString(@"Acquired Location", @"Acquired Location")];

            // we can also cancel our previous performSelector:withObject:afterDelay: - it's no longer necessary
            [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopUpdatingLocation:) object:nil];
        }
    }
}

Espero que esto ayude!

A través de GetLocationViewController.m en el proyecto de ejemplo "Localice" de Apple, disponible en:

Https://developer.apple.com/library/content/samplecode/LocateMe/Introduction/Intro.html

 45
Author: donkim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-29 15:03:53

De la respuesta de donkim considere reemplazar esta línea

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopUpdatingLocation:) object:nil];

Con línea

[NSObject cancelPreviousPerformRequestsWithTarget: self];
 0
Author: M.Y.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-16 07:16:37