1)新建桥接头文件(放在工程路径下),这里命名为BNaviSwiftDemo-Bridging-Header.h,在该头文件中import需要的库文件,代码如下:
#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件#import <BaiduMapAPI_Map/BMKMapView.h>//只引入所需的单个头文件#import "BNaviService.h"#import "BNRoutePlanModel.h"#import "BMTruckInfoModel.h"#import "BNDriveRouteProtocol.h"#import "BNCarRouteData.h"#import "BNaviModel.h"#import "BNLocationManagerProtocol.h"
2)左侧目录中选中工程名,在TARGETS->Build Settings-> Swift Compiler - Code Generation -> Objective-C Briding Header中输入桥接文件的路径, 如下图所示:
在AppDelegate.swift的didFinishLaunchingWithOptions方法的最前面配置百度导航Key。示例代码如下:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Override point for customization after application launch.initMapSDK()initNaviSDK()return true}func initMapSDK() {BMKMapManager.setAgreePrivacy(true);let mapManager = BMKMapManager()// 启动引擎并设置AK并设置delegateif !(mapManager.start("在此处输入您的授权AK", generalDelegate: self)) {}}func initNaviSDK() {BNaviService.setAgreePrivacy(true)BNaviService.getInstance().initNaviService(Dictionary()) {BNaviService.getInstance().authorizeNaviAppKey("你的key") { succ in}BNaviService.getInstance().authorizeTTSAppId("appId", apiKey: "apikey", secretKey: "secretKey") { isSuc in}} fail: {}}
算路请参考文档:驾车路线规划
导航请参考文档: 实时导航与模拟导航
上一篇
下一篇
本篇文章对您是否有帮助?