0

このコードから都市、州、住所のように分割する方法を知っている人はいますか? 住所全体が返されますが、市と州のみが必要です。

//Geocoding Block
[_geoCoder2 reverseGeocodeLocation: _currentLocation2.location completionHandler:
 ^(NSArray *placemarks, NSError *error) {

     //Get nearby address
     CLPlacemark *placemark = [placemarks objectAtIndex:0];

     //String to hold address
     NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];

     //Print the location to console
     NSLog(@"I am currently at %@",locatedAt);

     //Set the label text to current location
     [_cityLabel setText:locatedAt];

 }];
4

2 に答える 2

-1
// Reverse Geocoding
NSLog(@"Resolving the Address");
[_geoCoder2 reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    if (error == nil && [placemarks count] > 0) {
        placemark = [placemarks lastObject];
        _cityLabel.text = [NSString stringWithFormat:@"%@\n%@\n",

                           placemark.locality,
                           placemark.administrativeArea];

    } else {
        NSLog(@"%@", error.debugDescription);
    }
} ];
于 2012-12-01T05:40:13.823 に答える