You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
15 KiB

//
// AMapLocationManager.h
// AMapLocationKit
//
// Created by AutoNavi on 15/10/22.
// Copyright © 2015年 Amap. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AMapFoundationKit/AMapServices.h>
#import "AMapLocationCommonObj.h"
#import "AMapLocationRegionObj.h"
/**
* @brief AMapLocatingCompletionBlock Block
* @param location
* @param regeocode
* @param error AMapLocationErrorCode
*/
typedef void (^AMapLocatingCompletionBlock)(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error);
@protocol AMapLocationManagerDelegate;
#pragma mark - AMapLocationManager
///AMapLocationManager类。初始化之前请设置 AMapServices 中的apikey(例如:[AMapServices sharedServices].apiKey = @"您的key"),否则将无法正常使用服务.
@interface AMapLocationManager : NSObject
///实现了 AMapLocationManagerDelegate 协议的类指针。
@property (nonatomic, weak) id<AMapLocationManagerDelegate> delegate;
///设定定位的最小更新距离。单位米,默认为 kCLDistanceFilterNone,表示只要检测到设备位置发生变化就会更新位置信息。
@property(nonatomic, assign) CLLocationDistance distanceFilter;
///设定期望的定位精度。单位米,默认为 kCLLocationAccuracyBest。定位服务会尽可能去获取满足desiredAccuracy的定位结果,但不保证一定会得到满足期望的结果。
///注意:设置为kCLLocationAccuracyBest或kCLLocationAccuracyBestForNavigation时,单次定位会在达到locationTimeout设定的时间后,将时间内获取到的最高精度的定位结果返回。
///⚠ 当iOS14及以上版本,模糊定位权限下可能拿不到设置精度的经纬度
@property(nonatomic, assign) CLLocationAccuracy desiredAccuracy;
///指定定位是否会被系统自动暂停。默认为NO。
@property(nonatomic, assign) BOOL pausesLocationUpdatesAutomatically;
///是否允许后台定位。默认为NO。只在iOS 9.0及之后起作用。设置为YES的时候必须保证 Background Modes 中的 Location updates 处于选中状态,否则会抛出异常。由于iOS系统限制,需要在定位未开始之前或定位停止之后,修改该属性的值才会有效果。
@property(nonatomic, assign) BOOL allowsBackgroundLocationUpdates;
///指定单次定位超时时间,默认为10s。最小值是2s。注意单次定位请求前设置。注意: 单次定位超时时间从确定了定位权限(非kCLAuthorizationStatusNotDetermined状态)后开始计算。
@property(nonatomic, assign) NSInteger locationTimeout;
///指定单次定位逆地理超时时间,默认为5s。最小值是2s。注意单次定位请求前设置。
@property(nonatomic, assign) NSInteger reGeocodeTimeout;
///连续定位是否返回逆地理信息,默认NO。
@property (nonatomic, assign) BOOL locatingWithReGeocode;
///逆地址语言类型,默认是AMapLocationRegionLanguageDefault
@property (nonatomic, assign) AMapLocationReGeocodeLanguage reGeocodeLanguage;
///获取被监控的region集合。
@property (nonatomic, readonly, copy) NSSet *monitoredRegions;
///检测是否存在虚拟定位风险,默认为NO,不检测。 \n注意:设置为YES时,单次定位通过 AMapLocatingCompletionBlock 的error给出虚拟定位风险提示;连续定位通过 amapLocationManager:didFailWithError: 方法的error给出虚拟定位风险提示。error格式为 error.domain==AMapLocationErrorDomain; error.code==AMapLocationErrorRiskOfFakeLocation; \n附带的error的详细信息参考 error.localizedDescription 中的描述以及 error.userInfo 中的信息(error.userInfo.AMapLocationRiskyLocateResult 表示有虚拟风险的定位结果; error.userInfo.AMapLocationAccessoryInfo 表示外接辅助设备信息)。
@property (nonatomic, assign) BOOL detectRiskOfFakeLocation;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
/**
* @brief AMapLocationAccuracyFullAndReduce\n
API\n
* \n
* | | doRequireTemporaryFullAccuracyAuth | / |\n
* | AMapLocationFullAndReduceAccuracy | | |\n
* | AMapLocationFullAccuracy | | error |\n
* | AMapLocationReduceAccuracy | | |\n
* \n
* AMapLocationFullAndReduceAccuracy时currentAuthorization判断当前是否是精确定位
* @since 2.6.7
*/
@property (nonatomic, assign) AMapLocationAccuracyMode locationAccuracyMode API_AVAILABLE(ios(14.0));
/**
* @brief
* @since 2.6.7
*/
@property (nonatomic, readonly) CLAccuracyAuthorization currentAuthorization API_AVAILABLE(ios(14.0));
#endif
/**
* @brief
* @return YES: ; NO:
*/
+ (BOOL)headingAvailable;
/**
* @brief
*/
- (void)startUpdatingHeading;
/**
* @brief
*/
- (void)stopUpdatingHeading;
/**
* @brief
*/
- (void)dismissHeadingCalibrationDisplay;
/**
* @brief NO\n该方法将会根据设定的 desiredAccuracy desiredAccuracy completionBlock返回精度最高的定位信息\n可以通过 stopUpdatingLocation
* @param withReGeocode ()
* @param completionBlock Block
* @return Request
*/
- (BOOL)requestLocationWithReGeocode:(BOOL)withReGeocode completionBlock:(AMapLocatingCompletionBlock)completionBlock;
/**
* @brief cancel掉所有的单次定位请求
*/
- (void)startUpdatingLocation;
/**
* @brief cancel掉所有的单次定位请求
*/
- (void)stopUpdatingLocation;
/**
* @brief regionidentifier的regionregion将会被移除 AMapLocationCircleRegion radius小的region
* @param region
*/
- (void)startMonitoringForRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
/**
* @brief region
* @param region
*/
- (void)stopMonitoringForRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
/**
* @brief region的当前状态amapLocationManager:didDetermineState:forRegion:
* @param region region
*/
- (void)requestStateForRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
#pragma mark - Privacy 隐私合规
/**
* @brief App是否显示隐私弹窗的状态SDK隐私协议内容的状态AMapLocationManager实例化之前调用. since 2.8.0
* @param showStatus
* @param containStatus SDK隐私协议状态
*/
+ (void)updatePrivacyShow:(AMapPrivacyShowStatus)showStatus privacyInfo:(AMapPrivacyInfoStatus)containStatus;
/**
* @brief SDK隐私协议状态AMapLocationManager实例化之前调用. since 2.8.0
* @param agreeStatus SDK隐私协议状态
*/
+ (void)updatePrivacyAgree:(AMapPrivacyAgreeStatus)agreeStatus;
@end
#pragma mark - AMapLocationManagerDelegate
///AMapLocationManagerDelegate 协议定义了发生错误时的错误回调方法,连续定位的回调方法等。
@protocol AMapLocationManagerDelegate <NSObject>
@optional
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
/**
* @brief 1plist配置NSLocationTemporaryUsageDescriptionDictionary2locationAccuracyMode设置为AMapLocationFullAndReduceAccuracy/AMapLocationFullAccuracy3API即可
* [manager requestTemporaryFullAccuracyAuthorizationWithPurposeKey:@"PurposeKey" completion:^(NSError *error){
* if(completion){
* completion(error);
* }
* }]; (,)
* @param manager AMapLocationManager
* @param locationManager locationManager
* @param completion API回调结果error: error即可
* @since 2.6.7
*/
- (void)amapLocationManager:(AMapLocationManager *)manager doRequireTemporaryFullAccuracyAuth:(CLLocationManager*)locationManager completion:(void(^)(NSError *error))completion;
#endif
/**
* @brief plist配置NSLocationAlwaysUsageDescription或者NSLocationAlwaysAndWhenInUseUsageDescription[CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined
API即可[locationManager requestAlwaysAuthorization] (,)
* @param manager AMapLocationManager
* @param locationManager locationManager
* @since 2.6.2
*/
- (void)amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager*)locationManager;
/**
* @brief
* @param manager AMapLocationManager
* @param error CLError
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error;
/**
* @brief .amapLocationManager:didUpdateLocation:reGeocode:
* @param manager AMapLocationManager
* @param location
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location;
/**
* @brief .amapLocationManager:didUpdateLocation:
* @param manager AMapLocationManager
* @param location
* @param reGeocode
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode;
/**
* @brief iOS13及之前版本回调
* @param manager AMapLocationManager
* @param status
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
/**
* @brief iOS14及之后版本回调
* @param manager AMapLocationManager
* @param locationManager CLLocationManager类locationManager.authorizationStatus获取定位权限locationManager.accuracyAuthorization获取定位精度权限
*/
- (void)amapLocationManager:(AMapLocationManager *)manager locationManagerDidChangeAuthorization:(CLLocationManager*)locationManager;
/**
* @brief
* @param manager AMapLocationManager
* @return
*/
- (BOOL)amapLocationManagerShouldDisplayHeadingCalibration:(AMapLocationManager *)manager;
/**
* @brief
* @param manager AMapLocationManager
* @param newHeading
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading;
/**
* @brief region回调函数
* @param manager AMapLocationManager
* @param region region
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didStartMonitoringForRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
/**
* @brief region回调函数
* @param manager AMapLocationManager
* @param region region
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didEnterRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
/**
* @brief region回调函数
* @param manager AMapLocationManager
* @param region region
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didExitRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
/**
* @brief region状态回调函数
* @param manager AMapLocationManager
* @param state region的状态
* @param region region
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didDetermineState:(AMapLocationRegionState)state forRegion:(AMapLocationRegion *)region __attribute__((deprecated("请使用AMapGeoFenceManager")));
/**
* @brief region失败回调函数
* @param manager AMapLocationManager
* @param region region
* @param error AMapLocationErrorCode
*/
- (void)amapLocationManager:(AMapLocationManager *)manager monitoringDidFailForRegion:(AMapLocationRegion *)region withError:(NSError *)error __attribute__((deprecated("请使用AMapGeoFenceManager")));
@end