地理编码&反地理编码

“头脑可以接受劝告,但心却不能,而爱,因为没学地理,所以不识边界。“——杜鲁门·卡波特《别的声音,别的房间》

地理编码

1
2
3
4
CLGeocoder *geoCode = [[CLGeocoder alloc] init];
[geoCode geocodeAddressString:@"广州" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
NSLog(@"地理编码成功");
}];

反地理编码

1
2
3
4
CLGeocoder *geoCode = [[CLGeocoder alloc] init];
[geoCode reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:21.123 longitude:116.345] completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
NSLog(@"反地理编码成功");
}];

CLPlacemark地标对象详解

说明 属性 addressDictionary(KEY)
具体位置 name Name
街道 thoroughfare Thoroughfare
子街道(门牌号) subThoroughfare SubThoroughfare
locality City
subLocality SubLocality
省(州) administrativeArea State
其他行程信息(县镇乡) subAdministrativeArea
邮政编码 postalCode
国家代码 ISOcountryCode CountryCode
国家 country Country
水源 inlandWater
海洋 ocean
关联的或利益关系的地标 areasOfInterest
包含街道和子街道 Street
包含最详细的地址 FormattedAddressLines

本文作者: WalkerZ

本文链接: https://walkerzhan.github.io/2017/07/18/地理编码&反地理编码/

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!