如何从AddressDictionary获取格式化地址NSString? [英] How to get formatted address NSString from AddressDictionary?

查看:509
本文介绍了如何从AddressDictionary获取格式化地址NSString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从AddressDictionary获取格式化地址,这是我从CLGeocoder获得的。
使用以下代码但没有结果:

Trying to get formatted address from AddressDictionary, that I got from CLGeocoder. Used following code with no result:

subtitle = [NSString stringWithString:[[addressDict objectForKey:@"FormattedAddressLines"]objectAtIndex:0]];

还试过:

subtitle = [[[ABAddressBook sharedAddressBook] formattedAddressFromDictionary:placemark.addressDictionary] string];

但此代码似乎仅适用于Mac OS X.

but this code seems working on Mac OS X only.

编译器询问ABAdressBook,但我导入了两个头文件。

Compiler asks about ABAdressBook, but I have both header files imported.

#import <AddressBook/ABAddressBook.h>
#import <AddressBook/AddressBook.h>


推荐答案

地址字典的文档属性说:


您可以格式化此词典的内容以获取完整地址
string而不是自己建立地址。要格式化
字典,请使用ABCreateStringWithAddressDictionary函数作为地址簿UI函数参考中描述的

You can format the contents of this dictionary to get a full address string as opposed to building the address yourself. To format the dictionary, use the ABCreateStringWithAddressDictionary function as described in Address Book UI Functions Reference.

所以添加并导入 AddressBookUI 框架并尝试:

So add and import the AddressBookUI framework and try:

subtitle = 
    ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO);

这篇关于如何从AddressDictionary获取格式化地址NSString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆