Beim Versuch CLGeocoder zu verwenden, habe ich dieses Beispiel aus einem Online-Tutorial: https://www.appcoda.com/how-to-get-current-location-iphone-user/Warum CLGecoder mit einem Array von "Ortsmarkierungen" verwenden?
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
// Reverse Geocoding
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
addressLabel.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
placemark.subThoroughfare, placemark.thoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else {
NSLog(@"%@", error.debugDescription);
}
} ];
}
Allerdings verstehe ich nicht ganz, warum es eine Reihe von „Ortsmarken“ in dem Abschluss-Handler teilnimmt und warum wir sollten das letzte Objekt von "Ortsmarkierungen" verwenden (ich sehe auch Leute, die das erste Objekt benutzen?).
Ich habe durch den Apfel Dokument lesen, aber jede gute Erklärung in Bezug auf die Verwendung nicht finden: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLGeocoder_class/