Hvis jeg ønsker å vise userLocation på kartet, og samtidig posten hvor brukeren befinner seg, er det en god idé å legge en observatør til userLocation.location og registrere steder, eller skal jeg fortsatt bruke CLLocationManager for innspilling bruker plassering og bruk mapView.showUserLocation for å vise brukerens nåværende posisjon (blå indikator)? Jeg ønsker å vise standard blå indikator støttes av MapKit API.
Også her er en grov eksempelkode:
- (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
// ...
}
Under panseret, jeg tror MKMapView bruker også CLLocationManager å få brukerens nåværende plassering? Så, vil dette skape problemer fordi jeg tror både CLLocationManager og MapView vil prøve å bruke samme stedstjenester? Vil det være noen konflikter og mangel på nøyaktig / nødvendig eller nåværende data?













