gpt4 book ai didi

iphone - CLPlacemark 的 "Name"

转载 作者:行者123 更新时间:2023-12-03 20:42:06 24 4
gpt4 key购买 nike

我正在尝试了解 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/

24 4 0