Als ik wil userLocation laten zien op de kaart, en op hetzelfde time record locatie van de gebruiker, is het een goed idee om een waarnemer aan userLocation.location de locaties toe te voegen en op te nemen, of moet ik nog steeds gebruik maken CLLocationManager voor het opnemen van locatie van de gebruiker en het gebruik mapView.showUserLocation om de huidige locatie van de gebruiker (blauw lampje) zien? Ik wil de standaard blauwe indicator ondersteund door de MapKit API te tonen.
Ook hier is een ruw voorbeeld code:
- (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
// ...
}
Onder de motorkap, ik denk dat MKMapView gebruikt ook CLLocationManager de huidige locatie van de gebruiker te krijgen? Dus, zal dit maakt geen problemen, omdat ik geloof zowel CLLocationManager en MapView zal proberen om te gebruiken op dezelfde locatie diensten? Zijn er conflicten en gebrek aan accurate / vereist of de huidige gegevens?













