如何为 MKPlacemark 创建地址字典?
placemark = [[MKPlacemark alloc]initWithCoordinate:storedCoordinate addressDictionary:addressDict];
我尝试创建字典用于上面的代码,但没有任何效果:(
NSDictionary *addressDict = [[NSDictionary alloc] initWithObjectsAndKeys:
location.countryCode, @"CountryCode",
location.country,@"kABPersonAddressCountryKey",
location.state, kABPersonAddressStateKey,
location.city, @"City",
location.street, kABPersonAddressStreetKey,
location.zip, kABPersonAddressZIPKey,
nil];
placemark = [[MKPlacemark alloc]initWithCoordinate:storedCoordinate addressDictionary:addressDict];
I tried to create dictionary to use for code above, but nothing works :(
NSDictionary *addressDict = [[NSDictionary alloc] initWithObjectsAndKeys:
location.countryCode, @"CountryCode",
location.country,@"kABPersonAddressCountryKey",
location.state, kABPersonAddressStateKey,
location.city, @"City",
location.street, kABPersonAddressStreetKey,
location.zip, kABPersonAddressZIPKey,
nil];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为 MKPlacemark 创建地址字典时,建议您使用 ABPerson 中定义的“地址属性”常量。请注意,由于这些常量的类型为 CFStringRef,因此您需要将它们转换为 (NSString *) 以便将它们用作 NSDictionary 中的键。
iOS 9+ 更新:使用新的联系人框架
When creating the addressDictionary for the MKPlacemark, it's recommended that you use the "Address Property" constants as defined within ABPerson. Note, since these constants are of type CFStringRef, so you will need to cast them to an (NSString *) in order to use them as keys within the NSDictionary.
Update for iOS 9+: Use new Contacts Framework
值得注意的是,您需要将“AddressBook.framework”添加到项目构建设置中。
还要导入您的标头(.h 文件):
然后在您的实现(.m 文件)中您可以使用:
Worth noting that you will need to add the 'AddressBook.framework' to your project build settings.
Also import in your header (.h file):
Then in your implementation (.m file) you can use: