我使用以下代码从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部分显示为字符串?
答案 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);
}];