項目中用到的是高德地圖,看到別人的微博中用的百度地圖也挺簡單,先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