iOS CoreLocation框架第三章—— CLGeocoder(地理编码器)和CLPlacemark(获取位置信息)


1.使用CLGeocoder可以完成“地理编码”和“反地理编码”

地理编码:根据给定的地名,获得具体的位置信息(比如经纬度、地址的全称等)

反地理编码:根据给定的经纬度,获得具体的位置信息

 

(1)地理编码方法

  - (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;

       - (void)geocodeAddressString:(NSString *)addressString inRegion:(nullable CLRegion *)region completionHandler:(CLGeocodeCompletionHandler)completionHandler;  

       - (void)geocodeAddressDictionary:(NSDictionary *)addressDictionary completionHandler:(CLGeocodeCompletionHandler)completionHandler;

(2)反地理编码方法

  - (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler;

 

2.CLGeocodeCompletionHandler

  当地理\反地理编码完成时,就会调用CLGeocodeCompletionHandler

  iOS CoreLocation框架第三章—— CLGeocoder(地理编码器)和CLPlacemark(获取位置信息)_第1张图片

这个block传递2个参数

error :当编码出错时(比如编码不出具体的信息)有值

placemarks :里面装着CLPlacemark对象

3.CLPlacemark

说明:CLPlacemark的字面意思是地标,封装详细的地址位置信息

地理位置     @property (nonatomic, readonly) CLLocation *location;  

区域       @property (nonatomic, readonly) CLRegion *region;

详细的地址信息   @property (nonatomic, readonly) NSDictionary *addressDictionary;

地址名称    @property (nonatomic, readonly) NSString *name;

城市      @property (nonatomic, readonly) NSString *locality;

 国家                    @property (nonatomic, readonly, copy, nullable) NSString *country; // eg. United States

海洋                     @property (nonatomic, readonly, copy, nullable) NSString *ocean; // eg. Pacific Ocean

@property (nonatomic, readonly, copy, nullable) NSString *thoroughfare; // street name, eg. Infinite Loop

@property (nonatomic, readonly, copy, nullable) NSString *subThoroughfare; // eg. 1

@property (nonatomic, readonly, copy, nullable) NSString *subLocality; // neighborhood, common name, eg. Mission District

@property (nonatomic, readonly, copy, nullable) NSString *administrativeArea; // state, eg. CA

@property (nonatomic, readonly, copy, nullable) NSString *subAdministrativeArea; // county, eg. Santa Clara

@property (nonatomic, readonly, copy, nullable) NSString *postalCode; // zip code, eg. 95014

@property (nonatomic, readonly, copy, nullable) NSString *ISOcountryCode; // eg. US

@property (nonatomic, readonly, copy, nullable) NSString *inlandWater; // eg. Lake Tahoe


@property (nonatomic, readonly, copy, nullable) NSArray<NSString *> *areasOfInterest; // eg. Golden Gate Park

 

你可能感兴趣的:(iOS CoreLocation框架第三章—— CLGeocoder(地理编码器)和CLPlacemark(获取位置信息))