[BNCoreServices_Instance initServices: @"itIDWOfDPlQo5camfY5GeqOK"];
[BNCoreServices_Instance startServicesAsyn:nil fail:nil];
此时运行,会有一百多个错误。因为需要加入导航SDK的一些依赖库。必须加入CoreTelephony.framework,libstdc++.6.0.9.tbd,
AVFoundation.framework,CoreMotion.framework,ImageIO.framework,AudioToolbox.framework,SystemConfiguration.framework。
再运行发现还是有错,因为语法错误。
_OBJC_CLASS_$_NSManagedObjectModel", referenced from:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_OBJC_CLASS_$_NSFetchRequest", referenced from:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_OBJC_CLASS_$_NSManagedObjectContext", referenced from:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_OBJC_CLASS_$_NSPersistentStoreCoordinator", referenced from:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_OBJC_CLASS_$_NSAttributeDescription", referenced from:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_OBJC_CLASS_$_NSEntityDescription", referenced from:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_NSSQLiteStoreType", referenced from:
-[BDETTSCoreDataHelper setupPersistentStore] in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
因为导航SDK的语法关系,需要在Build Settings中, “Other Linker Flags”添加“-ObjC” 标识。再运行,程序就没有问题了。注意添加时,O和C是大写,一个字母不对就会出错。
第五步:设置info.plist。一般思路,接下来当然是加导航代码,但是还得意识到一个问题,导航需要定位,因为真正的导航是从自己当前位置为起点的。
为了对iOS8的定位能力做兼容,做了相应的修改,开发者在使用过程中注意事项如下: 需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):
NSLocationWhenInUseUsageDescription ,允许在前台使用时获取GPS的描述
NSLocationAlwaysUsageDescription ,允许永久使用GPS的描述。
//发起导航
- (void)startNavi
{
//节点数组
NSMutableArray *nodesArray = [[NSMutableArray alloc] initWithCapacity:2];
//起点
BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
startNode.pos = [[BNPosition alloc] init];
startNode.pos.x = 113.936392;
startNode.pos.y = 22.547058;
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:nildelegete:self userInfo:nil];
}
//算路成功回调
-(void)routePlanDidFinished:(NSDictionary *)userInfo
{
NSLog(@"算路成功");
//路径规划成功,开始导航
[BNCoreServices_UI showNaviUI: BN_NaviTypeReal delegete:self isNeedLandscape:YES];
}
//算路失败回调
- (void)routePlanDidFailedWithError:(NSError *)error andUserInfo:(NSDictionary *)userInfo
{
NSLog(@"算路失败");
if ([error code] == BNRoutePlanError_LocationFailed) {
NSLog(@"获取地理位置失败");
}
else if ([error code] == BNRoutePlanError_LocationServiceClosed)
{
NSLog(@"定位服务未开启");
}
}
//算路取消回调
-(void)routePlanDidUserCanceled:(NSDictionary*)userInfo {
NSLog(@"算路取消");
}
#pragma mark - BNNaviUIManagerDelegate
//退出导航回调
-(void)onExitNaviUI:(NSDictionary*)extraInfo
{
NSLog(@"退出导航");
}
- (IBAction)StartNavAction:(id)sender {
if (![self checkServicesInited]) return;
_naviType = BN_NaviTypeReal;
[self startNavi];
}