全部服务产品
开发者频道
定价
登录
步骑行导航多实例
下载开发文档
步行导航功能实现
1. 注册多实例授权代理回调
BMKCycleNavigationManager *manager = [BMKCycleNavigationManager sharedManager];
// 0.注册授权代理回调
manager.authorizeDelegate = self;
manager.calcRouteDelegate = self;
manager.routeGuidanceDelegate = self;
manager.ttsPlayerDelegate = self;
manager.managerDelegate = self;
manager.locationAuthorizationDelegate = self;
manager.bottomButtonHeight = 70;
// 启用后台位置指示器,进入后台时保留被授予的临时访问权限(精确位置)
[manager showsBackgroundLocationIndicator:YES];
//BMKWalkCycleNavigationDisplayOption *displayOption = [[BMKWalkCycleNavigationDisplayOption alloc] init];
BMKMultiNaviViewController *controller = [[BMKMultiNaviViewControlleralloc] init];
controller.navigationType = BMK_WALK_CYCLE_NAVIGATION_TYPE_NORMAL_CYCLE;
2. 多实例授权

2.1 授权方案1

// 授权方案1:创建BMKWalkCycleNavigationOptions前,通过BMKCommonInfo设置过公共互联设备ID信息
// options.authorizeOption会有默认值
// [BMKCommonInfo setCommonShareDeviceID:@"123456789"];
BMKWalkCycleNavigationOptions *options = [[BMKWalkCycleNavigationOptionsalloc] init];
BMKWalkCycleNavigationDisplayOption *displayOption = [selfdispalyOption];
options.displayOption = displayOption;

2.2 授权方案2

// 授权方案2.初始化导航引擎时传入授权信息,创建并设置新的authorizeOption
BMKAuthorizeUserInfo *authorizeUserInfo = [[BMKAuthorizeUserInfoalloc] init];
authorizeUserInfo.ak = @"TcpqaFRLCK88zBCvcGw1fqEYysMsoExM";
authorizeUserInfo.deviceID = @"123456789";
options.authorizeOption = authorizeUserInfo;
3. 初始化导航manager
BOOL inited = [[BMKCycleNavigationManagersharedManager] initNaviEngine:controller options:options];
4. 创建导航视图多实例
if (inited) {
NSLog(@"SDK-初始化引擎成功");
// 2.创建导航视图多实例
BMKMultiNaviView *multiNaviView = [[BMKMultiNaviViewalloc] initWithFrame:CGRectMake(0, 150, 200, 300)];
// 3.根据导航视图多实例类型绑定导航数据源 注意:请在BMKWalkCycleAuthorizeDelegate授权代理回调中调用算路接口,否则多实例导航数据将绑定失败
BOOL bindFlag = [multiNaviView bindNaviDataSourceWithNaviType:BMK_WALK_CYCLE_NAVIGATION_TYPE_NORMAL_CYCLE];
if (bindFlag) {
NSLog(@"SDK-多实例导航数据绑定成功");
} else {
NSLog(@"SDK-多对实例导航数据绑定失败");
}
/// 多实例展示在合适位置,demo是传给了BMKMultiNaviViewController同屏展示
controller.multiNaviView = multiNaviView;
///[self.view addSubview:multiNaviView]; 也可以按需求addSubview到任何父视图
BMKCycleNaviLaunchParam *param = [[BMKCycleNaviLaunchParamalloc] init];
param.startPoint = CLLocationCoordinate2DMake(_startAnnotation.coordinate.latitude, _startAnnotation.coordinate.longitude);
param.endPoint = _endAnnotation.coordinate;
param.naviType = self.navigationType;
// 4.发起导航算路
[[BMKCycleNavigationManagersharedManager] routePlanWithParams:param];
}
5. 授权回调
#pragma mark - BMKWalkCycleAuthorizeDelegate
/**
多实例授权回调,授权失败时会自动解除多实例数据绑定
*/
- (void)onMultiNaviViewInstanceAuthorizeWithError:(BMKLicenseServiceErrorCode)errorCode serviceType:(BMKAuthorizeServiceType)serviceType {
switch (errorCode) {
caseBMK_LICENSE_SERVICE_NO_ERROR:
NSLog(@"授权成功!多实例同步显示导航信息");
break;
case BMK_LICENSE_SERVICE_INNER_ERROR:
case BMK_LICENSE_SERVICE_NETWOKR_ERROR:
case BMK_LICENSE_SERVICE_NETWOKR_TIMEOUT:
case BMK_LICENSE_SERVICE_SERVER_ERROR:
NSLog(@"网络和服务内部相关错误将不影响本次多实例同步显示导航信息");
break;
case BMK_LICENSE_SERVICE_NO_PERMISSION:
NSLog(@"授权失败!无相关高级权限,请联系商务或PM开通,多实例同步显示导航信息自动断开");
break;
caseBMK_LICENSE_SERVICE_LICENSE_STATUS_ERROR:
NSLog(@"授权失败!lincese授权状态失败,多实例同步显示导航信息自动断开");
break;
caseBMK_LICENSE_SERVICE_LICENSE_SIGN_ERROR:
NSLog(@"授权失败!lincese验签失败,多实例同步显示导航信息自动断开");
break;
caseBMK_LICENSE_SERVICE_PARAMETER_ERROR:
caseBMK_LICENSE_SERVICE_MODE_ERROR:
NSLog(@"授权失败!参数异常,多实例同步显示导航信息自动断开");
break;
caseBMK_LICENSE_SERVICE_NO_QUOTA:
caseBMK_LICENSE_SERVICE_QUOTA_NO_ENOUGH:
caseBMK_LICENSE_SERVICE_QUOTA_INVALID:
NSLog(@"授权失败!设备lincese配额异常,多实例同步显示导航信息自动断开");
break;
default:
NSLog(@"未知异常,多实例同步显示导航信息自动断开");
break;
}
}
主导航及多实例生命周期

以BMKMultiNaviViewController生命周期为参考

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// 0.添加多实例View
[self.view addSubview:self.multiNaviView];
if (self.navigationType == BMK_WALK_CYCLE_NAVIGATION_TYPE_WALK) {
// 1.步行导航恢复
[[BMKWalkNavigationManager sharedManager] resume];
} else {
//1. 骑行导航恢复
[[BMKCycleNavigationManager sharedManager] resume];
}
// 2.恢复多实例导航View
[self.multiNaviView onResume];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (self.navigationType == BMK_WALK_CYCLE_NAVIGATION_TYPE_WALK) {
// 3.步行导航暂停
[[BMKWalkNavigationManager sharedManager] pause];
} else {
// 3.骑行导航暂停
[[BMKCycleNavigationManager sharedManager] pause];
}
// 4.暂停多实例导航View
[self.multiNaviView onPause];
}
- (void)viewDidDisappear:(BOOL)animated {
// 5.移除多实例导航view
[self.multiNaviView removeFromSuperview];
// 6.销毁多实例导航view
[self.multiNaviView onDestroy];
if (self.navigationType == BMK_WALK_CYCLE_NAVIGATION_TYPE_WALK) {
// 7.停止步行导航
[[BMKWalkNavigationManager sharedManager] stop];
// 8.销毁步行导航manager
[BMKWalkNavigationManager destroy];
} else {
// 7.停止骑行导航
[[BMKCycleNavigationManager sharedManager] stop];
// 8.销毁骑行导航manager
[BMKCycleNavigationManager destroy];
}
}

上一篇

导航路线及诱导信息

下一篇

步骑行导航后台投屏

本篇文章对您是否有帮助?