我正在使用此代碼獲取地標,但未給出城市名稱。 早些時候我使用MKReverse地理編碼器來獲取我正在獲取城市名稱的地標,但在iOS 6中它顯示不推薦使用,因爲Apple開發人員在CLLocation中添加了所有內容。iOS 6中未給出城市名稱的地標6
所以我用這個代碼:
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *location = [locationManager location];
NSLog(@"location is %@",location);
CLGeocoder *fgeo = [[[CLGeocoder alloc] init] autorelease];
// Reverse Geocode a CLLocation to a CLPlacemark
[fgeo reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error){
// Make sure the geocoder did not produce an error
// before continuing
if(!error){
// Iterate through all of the placemarks returned
// and output them to the console
for(CLPlacemark *placemark in placemarks){
NSLog(@"%@",[placemark description]);
city1= [placemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey];
NSLog(@"city is %@",city1);
}
}
else{
// Our geocoder had an error, output a message
// to the console
NSLog(@"There was a reverse geocoding error\n%@",
[error localizedDescription]);
}
}
];
}
這裏,因爲我在控制檯我看到在NSLog(@"%@",[placemark description]);
它給像輸出: - ABC路名abc路名,國家名,國家名稱。
對不起,這個答案不是那麼清楚的結果,因爲我一直在想你的問題是試圖登錄所有的字典,只有現在我閱讀了帖子標題中的真實問題......你是否使用FormattedAddressLines看到了這個城市?你的代碼看起來很好,你有沒有嘗試過另一個位置? – LombaX