【问题标题】:convert MKPlaceMark addressDictionary string encoded转换 MKPlaceMark 地址字典字符串编码
【发布时间】:2011-08-02 01:00:07
【问题描述】:

我正在研究一个使用 MKReverseGeocoder 将经纬度转换为地址的示例。但是当我收到数据并尝试获取结果时,我收到的字符串如下:

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

我收到了这样的地址:“Ng\U00f5 381 Nguy\U1ec5n Khang”

如何将其转换为 unicode 格式的字符串?

提前致谢。

【问题讨论】:

    标签: iphone mkreversegeocoder


    【解决方案1】:

    如果您从 MKRevereseGeocoder 委托回调中获取 MKPlaceMark 对象,您可以使用以下方法将地标转换为可读地址:

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

    您需要将 AddressBookUI 框架添加到您的项目中并

    #import <AddressBookUI/AddressBookUI.h>
    

    也是。

    我不确定响应是 unicode,但看起来它可以合理地表示地标中的所有数据。

    未经测试,但是

    NSLog(@"Address of placemark: %@", [CNPostalAddressFormatter stringFromPostalAddress:placeMark.postalAddress style:CNPostalAddressFormatterStyleMailingAddress]);
    

    所需的框架是“联系人”,因此请包含以下内容:

    @import Contacts;
    

    应该是iOS11.0+的新做事方式

    【讨论】:

    • developer.apple.com/library/ios/#documentation/AddressBookUI/… Apple 建议:“您可以格式化此字典的内容以获得完整的地址字符串,而不是自己构建地址。要格式化字典,请使用地址中所述的 ABCreateStringWithAddressDictionary 函数预订 UI 函数参考。”
    • 由于 iOS 9.0 ABCreateStringWithAddressDictionary 已弃用。
    • 我需要 ios 9+ 的解决方案
    【解决方案2】:

    如果您从 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]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多