定位相关设置与回调 最后更新时间: 2021年01月22日
导航SDK是强依赖定位的,当您初始化AMapNaviDriveManager时,SDK内部会自行调用系统定位(CLLocationManager)的相关方法。如果需要在后台导航,AMapNaviBaseManager的下面两个接口是您需要注意的:
///指定定位是否会被系统自动暂停。默认为YES。
@property(nonatomic, assign) BOOL pausesLocationUpdatesAutomatically;
///是否允许后台定位.默认为NO(只在iOS 9.0及以后版本起作用).注意:设置为YES的时候必须保证 Background Modes 中的 Location updates 处于选中状态,否则会抛出异常.
@property (nonatomic, assign) BOOL allowsBackgroundLocationUpdates;
必须进行如下设置:
[[AMapNaviDriveManager sharedInstance] setPausesLocationUpdatesAutomatically:NO];
[[AMapNaviDriveManager sharedInstance] setAllowsBackgroundLocationUpdates:YES];
AMapNaviDriveManager.sharedInstance().allowsBackgroundLocationUpdates = true
AMapNaviDriveManager.sharedInstance().pausesLocationUpdatesAutomatically = false
驾车导航的定位点信息是通过<AMapNaviDriveDataRepresentable>协议的如下回调返回的:
///当前的自车位置
@interface AMapNaviLocation : NSObject<NSCopying>
///经纬度
@property (nonatomic, strong) AMapNaviPoint *coordinate;
///精确度
@property (nonatomic, assign) double accuracy;
///高度
@property (nonatomic, assign) double altitude;
///方向
@property (nonatomic, assign) double heading;
///速度(km/h)
@property (nonatomic, assign) NSInteger speed;
///时间戳
@property (nonatomic, strong) NSDate *timestamp;
///是否匹配在道路上
@property (nonatomic, assign) BOOL isMatchNaviPath;
///当前所在的segment段的index,从0开始 since 6.7.0
@property (nonatomic, assign) int currentSegmentIndex;
///当前所在的link段的index,从0开始 since 6.7.0
@property (nonatomic, assign) int currentLinkIndex;
///当前自车位置在当前link段所在的point的index,从0开始 since 6.7.0
@property (nonatomic, assign) int currentPointIndex;
///当前定位点是否为参与导航的网络点. 注意:只针对驾车. since 6.8.0
@property (nonatomic, assign) BOOL isNetworkNavi;
@end
/**
* @brief 自车位置更新回调 (since 5.0.0,模拟导航和实时导航的自车位置更新都会走此回调)
* @param driveManager 驾车导航管理类
* @param naviLocation 自车位置信息,参考 AMapNaviLocation 类
*/
- (void)driveManager:(AMapNaviDriveManager *)driveManager updateNaviLocation:(nullable AMapNaviLocation *)naviLocation;