AMapLocationManager.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // AMapLocationManager.h
  3. // AMapLocationKit
  4. //
  5. // Created by AutoNavi on 15/10/22.
  6. // Copyright © 2015年 Amap. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "AMapLocationCommonObj.h"
  10. #import "AMapLocationRegionObj.h"
  11. /**
  12. * @brief AMapLocatingCompletionBlock 单次定位返回Block
  13. * @param location 定位信息
  14. * @param regeocode 逆地理信息
  15. * @param error 错误信息,参考 AMapLocationErrorCode
  16. */
  17. typedef void (^AMapLocatingCompletionBlock)(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error);
  18. @protocol AMapLocationManagerDelegate;
  19. #pragma mark - AMapLocationManager
  20. ///MapLocationManager类。初始化之前请设置 AMapLocationServices 中的APIKey,否则将无法正常使用服务.
  21. @interface AMapLocationManager : NSObject
  22. ///实现了 AMapLocationManagerDelegate 协议的类指针。
  23. @property (nonatomic, weak) id<AMapLocationManagerDelegate> delegate;
  24. ///设定定位的最小更新距离。默认为 kCLDistanceFilterNone。
  25. @property(nonatomic, assign) CLLocationDistance distanceFilter;
  26. ///设定定位精度。默认为 kCLLocationAccuracyBest。
  27. @property(nonatomic, assign) CLLocationAccuracy desiredAccuracy;
  28. ///指定定位是否会被系统自动暂停。默认为NO。
  29. @property(nonatomic, assign) BOOL pausesLocationUpdatesAutomatically;
  30. ///是否允许后台定位。默认为NO。只在iOS 9.0及之后起作用。设置为YES的时候必须保证 Background Modes 中的 Location updates 处于选中状态,否则会抛出异常。由于iOS系统限制,需要在定位未开始之前或定位停止之后,修改该属性的值才会有效果。
  31. @property(nonatomic, assign) BOOL allowsBackgroundLocationUpdates;
  32. ///指定单次定位超时时间,默认为10s。最小值是2s。注意单次定位请求前设置。注意: 单次定位超时时间从确定了定位权限(非kCLAuthorizationStatusNotDetermined状态)后开始计算。
  33. @property(nonatomic, assign) NSInteger locationTimeout;
  34. ///指定单次定位逆地理超时时间,默认为5s。最小值是2s。注意单次定位请求前设置。
  35. @property(nonatomic, assign) NSInteger reGeocodeTimeout;
  36. ///连续定位是否返回逆地理信息,默认NO。
  37. @property (nonatomic, assign) BOOL locatingWithReGeocode;
  38. ///获取被监控的region集合。
  39. @property (nonatomic, readonly, copy) NSSet *monitoredRegions;
  40. /**
  41. * @brief 单次定位。如果当前正在连续定位,调用此方法将会失败,返回NO。\n该方法将会根据设定的 desiredAccuracy 去获取定位信息。如果获取的定位信息精确度低于 desiredAccuracy ,将会持续的等待定位信息,直到超时后通过completionBlock返回精度最高的定位信息。\n可以通过 stopUpdatingLocation 方法去取消正在进行的单次定位请求。
  42. * @param withReGeocode 是否带有逆地理信息(获取逆地理信息需要联网)
  43. * @param completionBlock 单次定位完成后的Block
  44. * @return 是否成功添加单次定位Request
  45. */
  46. - (BOOL)requestLocationWithReGeocode:(BOOL)withReGeocode completionBlock:(AMapLocatingCompletionBlock)completionBlock;
  47. /**
  48. * @brief 开始连续定位。调用此方法会cancel掉所有的单次定位请求。
  49. */
  50. - (void)startUpdatingLocation;
  51. /**
  52. * @brief 停止连续定位。调用此方法会cancel掉所有的单次定位请求,可以用来取消单次定位。
  53. */
  54. - (void)stopUpdatingLocation;
  55. /**
  56. * @brief 开始监控指定的region。如果已经存在相同identifier的region,则之前的region将会被移除。对 AMapLocationCircleRegion 类实例,将会优先监控radius小的region。
  57. * @param region 要被监控的范围
  58. */
  59. - (void)startMonitoringForRegion:(AMapLocationRegion *)region;
  60. /**
  61. * @brief 停止监控指定的region
  62. * @param region 要停止监控的范围
  63. */
  64. - (void)stopMonitoringForRegion:(AMapLocationRegion *)region;
  65. /**
  66. * @brief 查询一个region的当前状态。查询结果通过amapLocationManager:didDetermineState:forRegion:回调返回
  67. * @param region 要查询的region
  68. */
  69. - (void)requestStateForRegion:(AMapLocationRegion *)region;
  70. @end
  71. #pragma mark - AMapLocationManagerDelegate
  72. ///AMapLocationManagerDelegate 协议定义了发生错误时的错误回调方法,连续定位的回调方法等。
  73. @protocol AMapLocationManagerDelegate <NSObject>
  74. @optional
  75. /**
  76. * @brief 当定位发生错误时,会调用代理的此方法。
  77. * @param manager 定位 AMapLocationManager 类。
  78. * @param error 返回的错误,参考 CLError 。
  79. */
  80. - (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error;
  81. /**
  82. * @brief 连续定位回调函数.注意:本方法已被废弃,如果实现了amapLocationManager:didUpdateLocation:reGeocode:方法,则本方法将不会回调。
  83. * @param manager 定位 AMapLocationManager 类。
  84. * @param location 定位结果。
  85. */
  86. - (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location;
  87. /**
  88. * @brief 连续定位回调函数.注意:如果实现了本方法,则定位信息不会通过amapLocationManager:didUpdateLocation:方法回调。
  89. * @param manager 定位 AMapLocationManager 类。
  90. * @param location 定位结果。
  91. * @param reGeocode 逆地理信息。
  92. */
  93. - (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode;
  94. /**
  95. * @brief 定位权限状态改变时回调函数
  96. * @param manager 定位 AMapLocationManager 类。
  97. * @param status 定位权限状态。
  98. */
  99. - (void)amapLocationManager:(AMapLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
  100. /**
  101. * @brief 开始监控region回调函数
  102. * @param manager 定位 AMapLocationManager 类。
  103. * @param region 开始监控的region。
  104. */
  105. - (void)amapLocationManager:(AMapLocationManager *)manager didStartMonitoringForRegion:(AMapLocationRegion *)region;
  106. /**
  107. * @brief 进入region回调函数
  108. * @param manager 定位 AMapLocationManager 类。
  109. * @param region 进入的region。
  110. */
  111. - (void)amapLocationManager:(AMapLocationManager *)manager didEnterRegion:(AMapLocationRegion *)region;
  112. /**
  113. * @brief 离开region回调函数
  114. * @param manager 定位 AMapLocationManager 类。
  115. * @param region 离开的region。
  116. */
  117. - (void)amapLocationManager:(AMapLocationManager *)manager didExitRegion:(AMapLocationRegion *)region;
  118. /**
  119. * @brief 查询region状态回调函数
  120. * @param manager 定位 AMapLocationManager 类。
  121. * @param state 查询的region的状态。
  122. * @param region 查询的region。
  123. */
  124. - (void)amapLocationManager:(AMapLocationManager *)manager didDetermineState:(AMapLocationRegionState)state forRegion:(AMapLocationRegion *)region;
  125. /**
  126. * @brief 监控region失败回调函数
  127. * @param manager 定位 AMapLocationManager 类。
  128. * @param region 失败的region。
  129. * @param error 错误信息,参考 AMapLocationErrorCode 。
  130. */
  131. - (void)amapLocationManager:(AMapLocationManager *)manager monitoringDidFailForRegion:(AMapLocationRegion *)region withError:(NSError *)error;
  132. @end