2010-12-22 83 views
1

我想根据我的地理位置获取城市名称。问题是我在这个方法中得到了标题的编译时错误。我做错了什么?kABPersonAddressCityKey未声明的问题

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    MKPlacemark * myPlacemark = placemark; 
    // with the placemark you can now retrieve the city name 
    NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey]; 
} 

回答

11

这个常量来自AddressBook框架,尽管它也在其外部使用。尝试导入AddressBook标头以解决您的问题:

#import <AddressBook/AddressBook.h> 
+0

谢谢,就是这样:) – 1110 2010-12-22 09:55:17

0

由于iOS9您必须使用CNPostalAddressCityKey常量。