一: 在 http://lbsyun.baidu.com/index.php?title=ios-navsdk/sdkios-nav-download 下载导航的BaiduNaviSDK,并添加到工程里面。

二: 把baiduNaviSDK文件夹添加到工程中
把UserNotifications.framework、AudioToolbox.framework、ImageIO.framework、CoreMotion.framework、CoreLocation.framework、CoreTelephony.framework、MediaPlayer.framework、AVFoundation.framework、SystemConfiguration.framework、JavaScriptCore.framework、Security.framework 、OpenGLES.framework 、GLKit.framework 、libstdc++6.0.9.dylib、libc++.tbd、libsqlite3.0.tbd、libz.1.2.5.tbd这几个framework添加到工程中,添加方法为在Xcode中单击工程文件,选择Build Phrases选项,点击Link Binary with Libraries下的“+”逐个添加。另外thirdlibs中的两个静态库libssl.a、libcrypto.a也要添加到工程中,如下所示:

三 : 配置.plist文件,如图所示(画红线字段):
设置 “Required background modes”、 “App Transport Security Settings”(可以根据自身情况设置,导航sdk已经全面支持https)、 ”NSLocationAlwaysUsageDescription”、 ”NSLocationWhenInUseUsageDescription”、 ”View controller-based status bar appearance”、” LSApplicationQueriesSchemes”这6项

四: 开启引擎
在APPDelegate里面开启
//开启引擎
[BNCoreServices_Instance initServices:@"申请的密钥值"];
[BNCoreServices_Instance startServicesAsyn:nil fail:nil];
五: 发起导航
#pragma mark -- 发起导航
-(void)starNaviByBMKUserLocation:(BMKUserLocation *)userLocation{
//节点数组
NSMutableArray * nodesArray = [NSMutableArray array];
//起点
BNRoutePlanNode * startNode = [[BNRoutePlanNode alloc] init];
startNode.pos = [[BNPosition alloc] init];
startNode.pos.x = userLocation.location.coordinate.latitude;
startNode.pos.y = userLocation.location.coordinate.longitude;
startNode.pos.eType = BNCoordinate_BaiduMapSDK;
[nodesArray addObject:startNode];
//终点
BNRoutePlanNode * endNode = [[BNRoutePlanNode alloc] init];
endNode.pos = [[BNPosition alloc] init];
endNode.pos.x = userLocation.location.coordinate.latitude+ 10;
endNode.pos.y = userLocation.location.coordinate.longitude + 10;
endNode.pos.eType = BNCoordinate_BaiduMapSDK;
[nodesArray addObject:endNode];
//发起路径规划
[BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
}
#pragma mark -- BNNaviRoutePlanDelegate
-(void)routePlanDidFinished:(NSDictionary *)userInfo{
NSLog(@"路程计算成功");
//开始导航
[BNCoreServices_UI showPage:BNaviUI_NormalNavi delegate:self extParams:nil];
}
六: 运行结果如下(会出现错误):

网友评论