2011-04-09 18 views
4

我正在使用MKReverseGeocoder將lat,long轉換爲地址的示例。但是,當我接收到的數據,並試圖讓我接受字符串從如下結果:convert MKPlaceMark addressDictionary字符串編碼

NSString *street = [geocoder.addressDictionary objectForKey:@"Street"]; 

我收到這樣一個地址:「NG \ U00f5 381 Nguy \ U1ec5n安康山」

如何將它轉換爲unicode格式的字符串?

在此先感謝。

回答

16

如果您是從MKRevereseGeocoder委託回調得到MKPlaceMark對象返回您可以使用以下方法來打開標爲可讀地址:

NSLog(@"Address of placemark: %@", ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO)); 

您需要的AddressBookUI框架添加到您的項目,

#import <AddressBookUI/AddressBookUI.h> 

爲好。

我不確定響應是否爲unicode,但它看起來像是代表地標中所有數據的合理工作。

+0

http://developer.apple.com/library/ios /#documentation/AddressBookUI/Reference/AddressBookUI_Functions/Reference/reference.html Apple建議:「您可以格式化此字典的內容以獲取完整的地址字符串,而不是自己創建地址。要格式化字典,請使用ABCreateStringWithAddressDictionary函數如地址簿UI函數參考中所述。「 – 2011-12-15 21:45:44

+0

由於iOS 9.0'ABCreateStringWithAddressDictionary'已被棄用。 – mixel 2016-02-20 11:34:30

3

如果您是從MKRevereseGeocoder委託回調得到MKPlaceMark對象返回您可以使用以下方法來打開標爲可讀地址:

NSLog(@"The geocoder has returned: %@", [placemark addressDictionary]); 
//all elements returned 

//you can get some object like coutry ,code ;code country ... 

NSLog(@"country ::::%@",[placemark country]); 

NSLog(@"countrycode ::::%@",[placemark countryCode]); 

NSLog(@"postalcode ::::%@",[placemark postalcode]); 

NSLog(@"street::::%@",[placemark thoroughfare]); 

NSLog(@"streetinfo::::%@",[placemark administrativeArea]); 

NSLog(@"streeteersub ::::%@",[placemark subAdministrativeArea]);