iOS 使用CLGeocoder获取地理位置
placemark(MKPlacemark类的对象)其实是geocoder(MKReverseGeocoder类的对象)的一个属性。从geocoder里面取placemark这个和直接取placemark这个其实区别不大。而我们需要的信息主要就在这个里面了。
// 这个字典存放基础数据
@property (nonatomic, readonly) NSDictionary *addressDictionary;
让我们试试看,能从这个字典里面倒出来些什么东西。
以下是我用这个addressDictionary属性倒出来的字典。我们分析看看。
{
City = "\U897f\U5b89\U5e02";// 城市名字
Country = "\U4e2d\U56fd";// 国家名字
CountryCode = CN;// 国家编码
FormattedAddressLines = (
"\U4e2d\U56fd",
"\U9655\U897f\U7701\U897f\U5b89\U5e02\U96c1\U5854\U533a",
"\U9ad8\U65b0\U516d\U8def34\U53f7"
); // 这个应该是格式化后的地址了
State = "\U9655\U897f\U7701"; // 省
Street = "\U9ad8\U65b0\U516d\U8def 34\U53f7";// 街道完整名称
SubLocality = "\U96c1\U5854\U533a";//区名
SubLocality = "\U6816\U971e\U533a";
SubThoroughfare = "34\U53f7";//具体地址
Thoroughfare = "\U9ad8\U65b0\U516d\U8def";//街道名称
}
注意:上面的这个字典是可以直接转化为联系人的字典的,通过这个ABCreateStringWithAddressDictionary属性。
以下是placemark的其他属性。大家可以随意取用。
// address dictionary properties
@property (nonatomic, readonly) NSString *name; // eg. Apple Inc.
@property (nonatomic, readonly) NSString *thoroughfare; // street address, eg. 1 Infinite Loop
@property (nonatomic, readonly) NSString *subThoroughfare; // eg. 1
@property (nonatomic, readonly) NSString *locality; // city, eg. Cupertino
@property (nonatomic, readonly) NSString *subLocality; // neighborhood, common name, eg. Mission District
@property (nonatomic, readonly) NSString *administrativeArea; // state, eg. CA
@property (nonatomic, readonly) NSString *subAdministrativeArea; // county, eg. Santa Clara
@property (nonatomic, readonly) NSString *postalCode; // zip code, eg. 95014
@property (nonatomic, readonly) NSString *ISOcountryCode; // eg. US
@property (nonatomic, readonly) NSString *country; // eg. United States
@property (nonatomic, readonly) NSString *inlandWater; // eg. Lake Tahoe
@property (nonatomic, readonly) NSString *ocean; // eg. Pacific Ocean
@property (nonatomic, readonly) NSArray *areasOfInterest; // eg. Golden Gate Park