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];
最佳答案
在为 MKPlacemark 创建 addressDictionary 时,建议您使用 ABPerson 中定义的“地址属性”常量。请注意,由于这些常量是 CFStringRef 类型,因此您需要将它们转换为 (NSString *) 以便将它们用作 NSDictionary 中的键。
NSDictionary *addressDict = @{
(NSString *) kABPersonAddressStreetKey : location.street,
(NSString *) kABPersonAddressCityKey : location.city,
(NSString *) kABPersonAddressStateKey : location.state,
(NSString *) kABPersonAddressZIPKey : location.zip,
(NSString *) kABPersonAddressCountryKey : location.country,
(NSString *) kABPersonAddressCountryCodeKey : location.countryCode
};
iOS 9+ 更新:使用新的联系人框架
NSDictionary *addressDict = @{
CNPostalAddressStreetKey : location.street,
CNPostalAddressCityKey : location.city,
CNPostalAddressStateKey : location.state,
CNPostalAddressPostalCodeKey : location.zip,
CNPostalAddressCountryKey : location.country,
CNPostalAddressISOCountryCodeKey : location.countryCode
};
关于objective-c - 如何为 MKPlacemark 创建 addressDictionary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7786276/