[BNCoreServices_InstanceinitServices:@"itIDWOfDPlQo5camfY5GeqOK"];
[BNCoreServices_InstancestartServicesAsyn:nilfail: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", referencedfrom:
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", referencedfrom:
objc-class-ref in libbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
"_NSSQLiteStoreType", referenced from:
-[BDETTSCoreDataHelper setupPersistentStore] inlibbaiduNaviSDK.a(BDETTSCoreDataHelper.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to seeinvocation)
因为导航SDK的语法关系,需要在BuildSettings中, “Other Linker Flags”添加“-ObjC”标识。再运行,程序就没有问题了。注意添加时,O和C是大写,一个字母不对就会出错。
第五步:设置info.plist。一般思路,接下来当然是加导航代码,但是还得意识到一个问题,导航需要定位,因为真正的导航是从自己当前位置为起点的。
为了对iOS8的定位能力做兼容,做了相应的修改,开发者在使用过程中注意事项如下:需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):
NSLocationWhenInUseUsageDescription,允许在前台使用时获取GPS的描述
NSLocationAlwaysUsageDescription,允许永久使用GPS的描述。
如果仍有以下问题:,
请依照下图解决::
//发起导航
- (void)startNavi
{
//节点数组
NSMutableArray*nodesArray = [[NSMutableArrayalloc] initWithCapacity:2];
//起点
BNRoutePlanNode *startNode= [[BNRoutePlanNode alloc]init];
startNode.pos= [[BNPositionalloc]init];
startNode.pos.x=113.936392;
startNode.pos.y=22.547058;
startNode.pos.eType=BNCoordinate_BaiduMapSDK;
[nodesArrayaddObject:startNode];
//终点
BNRoutePlanNode *endNode= [[BNRoutePlanNode alloc]init];
endNode.pos= [[BNPositionalloc]init];
endNode.pos.x=114.077075;
endNode.pos.y=22.543634;
endNode.pos.eType=BNCoordinate_BaiduMapSDK;
[nodesArrayaddObject:endNode];
//发起路径规划
[BNCoreServices_RoutePlanstartNaviRoutePlan:BNRoutePlanMode_RecommendnaviNodes:nodesArraytime:nildelegete:selfuserInfo:nil];
}
//算路成功回调
-(void)routePlanDidFinished:(NSDictionary*)userInfo
{
NSLog(@"算路成功");
//路径规划成功,开始导航
[BNCoreServices_UIshowNaviUI:BN_NaviTypeReal delegete:selfisNeedLandscape:YES];
}
//算路失败回调
- (void)routePlanDidFailedWithError:(NSError*)error andUserInfo:(NSDictionary*)userInfo
{
NSLog(@"算路失败");
if([errorcode]== BNRoutePlanError_LocationFailed){
NSLog(@"获取地理位置失败");
}
elseif([errorcode]== BNRoutePlanError_LocationServiceClosed)
{
NSLog(@"定位服务未开启");
}
}
//算路取消回调
-(void)routePlanDidUserCanceled:(NSDictionary*)userInfo{
NSLog(@"算路取消");
}
#pragma mark - BNNaviUIManagerDelegate
//退出导航回调
-(void)onExitNaviUI:(NSDictionary*)extraInfo
{
NSLog(@"退出导航");
}
- (IBAction)StartNavAction:(id)sender{
if(![selfcheckServicesInited])return;
_naviType =BN_NaviTypeReal;
[selfstartNavi];
}