如何从CLGeocoder解析地标只显示城市

时间:2012-11-27 07:09:50

标签: xcode parsing mkmapview core-location clgeocoder

我使用以下代码从CLGeocoder接收地标,我想在同一个viewcontroller上只在另一个textview中显示该城市。我如何从这个阵列中解析出这座城市?它不是NSDictionary或任何东西,所以我不知道该怎么做。

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
    if (error){
        NSLog(@"Geocode failed with error: %@", error);
        return;
    }
    NSLog(@"Received placemarks: %@", placemarks);
}];

我对给定地标的记录如下:

< __ NSArrayM 0x1a0b3810>( 937-961 Sunnyvale Saratoga Rd,937-961 Sunnyvale Saratoga Rd,Sunnyvale,CA 94087,United States @< + 37.35984860,-122.03235910> +/- 100.00m )

< __ NSArrayM 0x19576ac0>( 5600 Van Nuys Blvd,5600 Van Nuys Blvd,Van Nuys,CA 91401-4602,United States @< + 34.17257000,-118.44794450> +/- 100.00m,区域(标识符< + 34.17257001,-118.44794464>半径57.64)< + 34.17257001,-118.44794464>半径57.64米 )

我怎样才能将Sunnyvale或Van Nuys部分显示为字符串?

1 个答案:

答案 0 :(得分:5)

使用CLPlacemark's properties

CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:yourLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  CLPlacemark *placemark = [placemarks objectAtIndex:0];
  NSString *strCity = [placemark locality];
  NSLog(@"%@",strCity);
}];