导航SDK的初始化时机建议在App启动的时候进行 ,在以下回调函数里进行导航SDK的初始化:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
导航SDK依赖地图SDK,需要先进行地图SDK的初始化。SDK初始化前需要先接受隐私权限。
详情见隐私权限。
-(void)initMapSDK {// 地图SDK隐私权限授权[BMKMapManager setAgreePrivacy:YES];BMKMapManager *mapManager = [[BMKMapManager alloc] init];self.mapManager = mapManager;// 如果要关注网络及授权验证事件,请设定generalDelegate参数[self.mapManager start:BNAVI_APP_KEY generalDelegate:nil];}
导航SDK初始化前需要先接受隐私权限。详情见隐私权限。
导航SDK初始化完成后,使用SDK前需要在SDK初始化成功的回调中进行导航SDK鉴权、TTS(语音播报)SDK鉴权,如果使用外部的TTS进行播报,可以不进行TTS SDK的鉴权。
- (void)initNaviSDK {///导航隐私授权 无授权无法使用导航[BNaviService setAgreePrivacy:YES];[BNaviService_Instance initNaviService:nil success:^{[BNaviService_Instance authorizeNaviAppKey:BNAVI_APP_KEYcompletion:^(BOOL suc) {}];[BNaviService_Instance authorizeTTSAppId:TTS_APP_IDapiKey:TTS_API_KEYsecretKey:TTS_SECRET_KEYcompletion:^(BOOL suc) {}];} fail:^{}];}
SDK初始化完成后,就可以进行路径规划,代码如下:
- (void)startRoutePlan {NSMutableArray *nodesArray = [NSMutableArray array];//起点BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];startNode.pos = [[BNPosition alloc] init];startNode.pos.x = 113.948682;startNode.pos.y = 22.530758;startNode.title = @"我的位置";startNode.pos.eType = BNCoordinate_BaiduMapSDK;[nodesArray addObject:startNode];//途经点BNRoutePlanNode *viaNode = [[BNRoutePlanNode alloc] init];viaNode.pos = [[BNPosition alloc] init];viaNode.pos.x = 113.980583;viaNode.pos.y = 22.542891;viaNode.title = @"世界之窗";viaNode.uid = @"e41eb1fb40abb0b82fb96db2";viaNode.pos.eType = BNCoordinate_BaiduMapSDK;[nodesArray addObject:viaNode];//终点BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];endNode.pos = [[BNPosition alloc] init];endNode.pos.x = 114.035529;endNode.pos.y = 22.615108;endNode.title = @"深圳北站";endNode.uid = @"6f6241e3c05ab1a093114c5e";endNode.pos.eType = BNCoordinate_BaiduMapSDK;[nodesArray addObject:endNode];//发起驾车路线规划[BNaviService_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:@{BNaviTripTypeKey:@(BN_NaviTypeReal)}];}
需要注意以下几点:
路径规划成功和失败的回调如下:
/*** 算路成功回调** @param userInfo 用户信息*/- (void)routePlanDidFinished:(NSDictionary*)userInfo;/*** 算路失败回调** @param error 失败信息* @param userInfo 用户信息*/- (void)routePlanDidFailedWithError:(NSError *)error andUserInfo:(NSDictionary*)userInfo;
算路完成后,即可发起导航,进入导航页面。需要在算路完成回调函数里跳转导航页面:
//算路成功回调-(void)routePlanDidFinished:(NSDictionary *)userInfo{//路径规划成功,跳转导航页面[BNaviService_UI showPage:BNaviUI_NormalNavi delegate:self extParams:@{BNaviUI_NormalNavi_TypeKey: @(BN_NaviTypeReal)}];}
和进入/退出导航页面主要的回调(BNNaviUIManagerDelegate)如下:
/*** 导航页面的调起controller* 可不实现,默认为最上层的controller*/- (id)naviPresentedViewController;/*** 即将退出UI的回调** @param pageType UI类型* @param extraInfo 额外参数*/- (void)willExitPage:(BNaviUIType)pageType extraInfo:(NSDictionary*)extraInfo;/*** 退出UI的回调** @param pageType UI类型* @param extraInfo 额外参数*/- (void)onExitPage:(BNaviUIType)pageType extraInfo:(NSDictionary*)extraInfo;
上一篇
下一篇
本篇文章对您是否有帮助?