iphone - CLPlacemark 的 "Name"

标签 iphone clgeocoder

我正在尝试了解 CLPlacemark 以及何时/如何为添加到 map 的图钉标注创建信息。在我几年前在更多 iOS 3 开发中读到的内容之前,他们对地址进行了反向地理编码并构建了地址(街道、邮政编码、州等)。首先,我需要自己构建这个字符串吗?我试图找出如何获取某些已知事物的位置名称,例如在下面的代码中搜索苹果商店:

NSString *address = @"1 stockton, san francisco, ca";    
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {

    [placemarks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSLog(@"obj description: %@", [obj description]);

        CLPlacemark *aPlacemark = (CLPlacemark *)obj;
        NSLog(@"%@", [aPlacemark.addressDictionary description]);
        NSLog(@"name: %@", ((CLPlacemark *)obj).name);
    }];
];

当我打印出描述时,我看到控制台显示:

Apple Store, San Francisco, 1 Stockton St, San Francisco, CA  94108-5805, United States @ <+37.78584545,-122.40651752> +/- 100.00m, region (identifier <+37.78584545,-122.40652161> radius 18.96) <+37.78584545,-122.40652161> radius 18.96m

旧金山苹果专卖店的名字从何而来?我以为它是 CLPlacemark.name 属性,但它是空的。因此,在尝试弄清楚 name 属性是如何创建的时,我发现:

        NSLog(@"%@", [aPlacemark.addressDictionary description]);

我得到输出:

City = "San Francisco";
Country = "United States";
CountryCode = US;
FormattedAddressLines =     (
    "Apple Store, San Francisco",
    "1 Stockton St",
    "San Francisco, CA  94108-5805",
    "United States"
);
PostCodeExtension = 5805;
State = California;
Street = "1 Stockton St";
SubAdministrativeArea = "San Francisco";
SubLocality = "Union Square";
SubThoroughfare = 1;
Thoroughfare = "Stockton St";
ZIP = 94108;

从中,我只能看到在addressDictionary的FormattedAddressLines键中,标题也在那里。

所以我想我的两个问题是:

1) 如果有位置(例如 Apple Store),我如何获取位置名称?

2)我是否还需要构建我的字符串,因为地址字典似乎已经为我构建了该字符串?

谢谢!

最佳答案

您可以使用AddressBookUI框架中的ABCreateStringWithAddressDictionary函数从CLPlacemark的“addressDictionary”属性中获取地址字符串。

关于iphone - CLPlacemark 的 "Name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12399220/

相关文章:

xcode - Swift 2 、 CLGeocoder() 和地标

swift - Xcode 10.3 模拟器问题?照片中的 PHAsset 位置和日期信息仅在一个模拟器中工作

Swift CLGeocoder 获取时区

ios - 设置包 - 如何删除它

ios - 如何以编程方式在 UIScrollView 中使用 AutoLayout 设置 subview ?

iphone - NavigationBar setShadowImage 并不总是有效

iphone - 是否可以在 iPhone 上录制 AAC/MP4 格式的音频?

iphone - 增加 TableView 标题的大小

swift - Swift 中的 CLGeocoder - 使用 reverseGeocodeLocation 时无法返回字符串

objective-c - 不在 Objective-C 中分配异步对象?