0

サンプルコードの一部を次に示します。

[_geoCoder reverseGeocodeLocation:self.locationManager.location // You can pass aLocation here instead
               completionHandler:^(NSArray *placemarks, NSError *error) {

                   dispatch_async(dispatch_get_main_queue(),^ {
                       // do stuff with placemarks on the main thread

                       if (placemarks.count == 1) {

                           CLPlacemark *place = [placemarks objectAtIndex:0];
                          // NSLog([place postalCode]);
                          NSString* addressString1 = [place thoroughfare];
                           addressString1 = [addressString1 stringByAppendingString:[NSString stringWithFormat:@"%@",[place.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey]]];//
                           NSLog(@"%@",addressString1);// is null ??
                           NSlog(@"%@",place.postalCode);//is null ??

                           //[self performSelectorInBackground:@selector(log) withObject:nil];
                       }

                   });
               }];
4

1 に答える 1

0

おそらく、郵便番号が存在しない「悪い」座標しかなかったと思います。次のスニペットを試してください。さまざまな情報と最後に郵便番号「80802」が表示されます。

CLLocationCoordinate2D myCoordinates = { 48.167222, 11.586111 };
CLLocation *location = [[CLLocation alloc]initWithLatitude:myCoordinates.latitude longitude:myCoordinates.longitude];

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"%d Placemarks %@", placemarks.count, placemarks);
    CLPlacemark *place = [placemarks objectAtIndex:0];
    NSLog(@"Placemark %@", place);
    NSLog(@"Address Dictionary: %@", place.addressDictionary);
    NSLog(@"Zip key %@", [place.addressDictionary objectForKey:(NSString *)kABPersonAddressZIPKey]);

}];

最初の行に別の座標を挿入して、自分で試してみてください。

于 2013-08-11T19:27:37.823 に答える