六、地标数据模型CLPlacemark
CLPlacemark是进行GEO编码后返回的地标对象,解析如下:
//初始化方法 使用另一个placemark拷贝
- (instancetype)initWithPlacemark:(CLPlacemark *) placemark;
//位置信息
@property (nonatomic, readonly, copy, nullable) CLLocation *location;
//区域范围信息
@property (nonatomic, readonly, copy, nullable) CLRegion *region;
//时区
@property (nonatomic, readonly, copy, nullable) NSTimeZone *timeZone;
//地理信息字典
@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary;
//地标名字
@property (nonatomic, readonly, copy, nullable) NSString *name;
//街道名字
@property (nonatomic, readonly, copy, nullable) NSString *thoroughfare;
//子街道名字
@property (nonatomic, readonly, copy, nullable) NSString *subThoroughfare;
//城镇
@property (nonatomic, readonly, copy, nullable) NSString *locality;
//子城镇
@property (nonatomic, readonly, copy, nullable) NSString *subLocality;
//州域信息
@property (nonatomic, readonly, copy, nullable) NSString *administrativeArea;
//子州域信息
@property (nonatomic, readonly, copy, nullable) NSString *subAdministrativeArea;
//邮编
@property (nonatomic, readonly, copy, nullable) NSString *postalCode;
//ISO国家编码
@property (nonatomic, readonly, copy, nullable) NSString *ISOcountryCode;
//国家
@property (nonatomic, readonly, copy, nullable) NSString *country;
//水域名称
@property (nonatomic, readonly, copy, nullable) NSString *inlandWater;
//海洋名称
@property (nonatomic, readonly, copy, nullable) NSString *ocean;
//相关的兴趣点数组
@property (nonatomic, readonly, copy, nullable) NSArray<NSString *> *areasOfInterest;
在CLPlacemark对象中有封装region对象,这个对象封装区域信息,如下:
//通过中心点和半径创建区域
- (instancetype)initCircularRegionWithCenter:(CLLocationCoordinate2D)center
radius:(CLLocationDistance)radius
identifier:(NSString *)identifier;
//区域中心
@property (readonly, nonatomic) CLLocationCoordinate2D center;
//半径
@property (readonly, nonatomic) CLLocationDistance radius;
//进入区域是否发出提醒 需要开启了位置区域监听
@property (nonatomic, assign) BOOL notifyOnEntry;
//离开区域是否发出提醒 需要开启了位置区域监听
@property (nonatomic, assign) BOOL notifyOnExit;
//检查某个点是否在区域内
- (BOOL)containsCoordinate:(CLLocationCoordinate2D)coordinate;
CLRegion类还有两个子类,CLCircularRegion类用来创建圆形区域,提供了一个便捷的初始化方法,其作用和CLRegion基本一致。CLBeaconRegion专门用来支持Beacon技术,Beacon技术是室内定位技术的一种,例如商场中有很多店铺,如果有店铺部署了Beacon发射设备,则当iOS设备作为接收设备靠近时会受到通知。CLBeaconRegion除了包含基础的区域信息外,还封装了与Beacon设备相关的设备码等信息。
七、区域访问功能
在iOS8之前,如果我们想获取用户是否在某个区域停留了一段时间是比较困难的,可能要多次定位并进行整理和分析。在iOS8后,CoreLocation框架中提供了方便的方法来处理这个问题。
首先,用户的区域停留可以理解为用户对某个区域进行了访问,开启和关闭访问监听十分方便,如下:
@interface CLLocationManager (CLVisitExtensions)
//开启服务
- (void)startMonitoringVisits;
//关闭服务
- (void)stopMonitoringVisits;
@end
开启后,当有相关的访问信息时,会回调代理中的相应函数,并且收到CLVisit对象,这个对象信息如下:
//访问开始时间
@property (nonatomic, readonly, copy) NSDate *arrivalDate;
//访问结束时间
@property (nonatomic, readonly, copy) NSDate *departureDate;
//位置
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
//精度
@property (nonatomic, readonly) CLLocationAccuracy horizontalAccuracy;