iPhone Development - CLLocationManager vs. MapKit

voti
6

Se voglio mostrare userLocation sulla mappa, e allo stesso tempo di record la posizione dell'utente, è una buona idea aggiungere un osservatore per userLocation.location e registrare le posizioni, o devo ancora usare CLLocationManager per la registrazione di posizione dell'utente e l'uso mapView.showUserLocation per mostrare posizione corrente dell'utente (indicatore blu)? Voglio mostrare l'indicatore blu di default supportati dalle API MapKit.

Inoltre, ecco un esempio di codice di massima:

- (void)viewDidLoad {
    ...

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = DISTANCE_FILTER_VALUE;
    locationManager.delegate = self; 
    [locationManager startUpdatingLocation];

    myMapView.showUserLocation = YES;
    [myMapView addObserver:self forKeyPath:@userLocation.location options:0 context:nil];

    ...
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    // Record the location information
    // ...
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    NSLog(@%s begins., __FUNCTION__);

    // Make sure that the location returned has the desired accuracy
    if (newLocation.horizontalAccuracy <= manager.desiredAccuracy)
        return;

    // Record the location information
    // ...
}

Sotto il cofano, penso MKMapView inoltre usa CLLocationManager per ottenere la posizione corrente dell'utente? Quindi, sarà questo crea alcun problema perché credo sia CLLocationManager e MapView cercheranno di utilizzare stessi servizi di localizzazione? Ci saranno conflitti e la mancanza di precisione / richiesta o dati attuali?

È pubblicato 07/04/2010 alle 07:49
fonte dall'utente
In altre lingue...                            


1 risposte

voti
1

Vedere questo ingresso SO : CLLocationManager utilizza gli stessi dati in tutte le sue istanze, quindi non c'è alcun conflitto.

Risposto il 07/04/2010 a 09:07
fonte dall'utente

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more