项目中用到的是高德地图,看到别人的微博中用的百度地图也挺简单,先MARK一下,用到了再说node
导入百度SDK,手动添加依赖库git
配置.plist文件数组
//***百度地图***//官网注册申请密钥key [BNCoreServices_Instance initServices:@"xxxxxxxxxxxxxxxxxxx"]; [BNCoreServices_Instance startServicesAsyn:nil fail:nil];
####用起点坐标和终点坐标计算路径app
#pragma mark 发起导航算路(起点和重点都放在这个方法里计算规划路径) - (void)startCalculateNavi { //***节点数组*** NSMutableArray *nodesArray = [[NSMutableArray alloc] initWithCapacity:2]; //***起点*** //得到当前定位 CLLocation *myLocation=[BNCoreServices_Location getLastLocation]; BNRoutePlanNode *startNode=[[BNRoutePlanNode alloc] init]; startNode.pos=[[BNPosition alloc] init]; startNode.pos.x=myLocation.coordinate.longitude; startNode.pos.y=myLocation.coordinate.latitude; startNode.pos.eType=BNCoordinate_OriginalGPS; //模拟定位点 // BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init]; // startNode.pos = [[BNPosition alloc] init]; // startNode.pos.x = 113.936392; // startNode.pos.y = 22.547058; ![Uploading baiduNavi_575714.gif . . .] // startNode.pos.eType = BNCoordinate_BaiduMapSDK; //将起始点加入到节点数组中 [nodesArray addObject:startNode]; //***终点*** BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init]; endNode.pos = [[BNPosition alloc] init]; endNode.pos.x = 114.077075; endNode.pos.y = 22.543634; endNode.pos.eType = BNCoordinate_BaiduMapSDK; [nodesArray addObject:endNode]; //***发起路径规划*** [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil]; }
#pragma mark 算路成功回调-(void)routePlanDidFinished:(NSDictionary *)userInfo{ NSLog(@"算路成功"); //路径规划成功,开始导航 [BNCoreServices_UI showPage:BNaviUI_NormalNavi delegate:self extParams:nil]; }
-(void)routePlanDidFailedWithError:(NSError *)error andUserInfo:(NSDictionary *)userInfo{ NSLog(@"导航失败"); }
集成排坑指南:ssh
1.官网百度导航SDK更新到了3.0.0,(3.0.0会有MBProgresshud等三方库冲突问题,若是你的项目中使用了这些三方库就会报错),解决方法:使用百度导航3.02;
2.百度导航 TTS受权失败,解决方法:去百度地图官网申请成为开发者,再添加项目申请密钥key;
3.百度导航SDK封装的静态库单个文件就有200多M,git时最好添加到忽略文件里。spa