算路,选路及上传路线,为了保持司机端和客户端路线一致,该部分接口由司乘同显导航sdk提供。
相关接口和回调在BNDriveRouteProtocol.h中。
///开始算路- (void)startRoutePlan {//获取订单[SCTXOrderSettingViewController getSharedOrder];BNRoutePlanNode* node1 = order.pickUpLocation;//BNRoutePlanNode的其他属性如果没有可以不传BNRoutePlanNode* node2 = order.endLocation;/**< 算路偏好,默认智能推荐 */self.strategy = [BNaviService_Strategy routePrefrence];//算路节点数组self.nodes = @[node1, node2];/*** 发起算路** @param strategy 算路方式,定义见BNRoutePlanStrategyType* @param naviNodes 算路节点数组,起点、途经点、终点按顺序排列,节点信息为BNRoutePlanNode结构* @param delegate 算路委托,用于回调* @param userInfo 用户需要传入的参数*/[BNaviService_RoutePlan startRoutePlan:(int)self.strategynaviNodes:@[node1, node2]delegete:selfuserInfo:nil];}
发起算路后,在算路成功的回调里,通过userInfo[BNRouteDataKey] 获取路线数据,如下:
- (void)routePlanDidFinished:(NSDictionary*)userInfo {BNMargin margin = {80,20,120,20};[BNaviService_DriveRoute showRouteViewAll:margin animated:NO];[self.threeTabView updateUI:userInfo[BNRouteDataKey]];self.selectIndex = 0;[self initMapSubView];}
该value为BNDriveRouteData*类型数据,结构体定义如下:
@interface BNDriveOneRouteData : NSObject//路线标签,比如距离最短,方案二@property (strong, nonatomic) NSString* routeLabelName;//预计行驶时间,单位为秒@property (assign, nonatomic) NSInteger time;//总路程,单位米@property (assign, nonatomic) NSInteger distance;//高速收费,单位¥@property (assign, nonatomic) NSInteger toll;//红绿灯个数@property (assign, nonatomic) NSInteger lightNum;@end@interface BNDriveRouteData : NSObject@property (strong, nonatomic) NSArray<BNDriveOneRouteData*>* routeAraay;@end
(1)BNDriveRouteProtocol相关接口和回调:
提供的接口如下:
@protocol BNDriveRouteManagerProtocol/**路线结果页面相关事件回调的delegate*/@property (weak, nonatomic,readwrite) id <BNDriveRouteManagerDelegate> delegate;/**全览路线@param margin 需要显示的路线范围的margin@param animated 全览是否需要动画*/- (void)showRouteViewAll:(BNMargin)margin animated:(BOOL)animated;/**选中路线,调用该接口后,同时会高亮该路线@param routeIndex 路线序号(从0开始)*/- (void)selectRouteAtIndex:(NSUInteger)routeIndex;/**确定使用选中的路线并上传到服务端,用于司机端发起算路导航@param routeIndex 路线序号,从0开始@param nodes 算路节点 (算路节点,把算路的算点数据回传)@param strategy 算路策略,定义见BNRoutePlanStrategyType(把算路的策略回传一下)@param order 订单信息@param extParam 额外参数,先预留,目前传nil@param completion 路线上传结束的回调*/- (void)postSelectRoute:(NSUInteger)routeIndexnodesArray:(NSArray<BNRoutePlanNode*>*)nodesroutePlanStrategy:(int)strategyorderInfo:(BNOrderInfo*)orderextParam:(NSDictionary*)extParamcompletion:(void (^)(NSDictionary* result, NSError* error))completion;/**地图即将显示,在viewWillAppear中调用*/- (void)viewWillAppear:(UIView*)parentView;/**地图即将隐藏,在viewWillDisAppear中调用*/- (void)viewWillDisAppear:(UIView*)parentView;/**销毁BNDriveRouteManager相关资源*/- (void)destory;@end
回调如下:
@protocol BNDriveRouteManagerDelegate/**用户在地图上点击了某条路线(如果需要高亮该路线,要调用selectRouteAtIndex:接口)@param routeIndex 路线序号(从0开始)*/- (void)onHandleTouchRouteAtIndex:(NSUInteger)routeIndex;@end
司机端在BNShareLocationProtocol.h中的两个接口:
(1)司乘同显模块所需要的数据回调
/**司乘同显模块所需要的数据回调*/@property (weak, nonatomic) id<BNShareLocationDataSource>dataSource;
(2)新增BNShareLocationDataSource协议,可以实现关闭乘客端选路需求
@protocol BNShareLocationDataSource<NSObject>@optional/**是否使用乘客端选择的路线,可选,不实现这个回调默认是NO@return 是否支持乘客端选路(返回YES的话,司机端会在送乘客阶段尝试拉取相关的路线数据,返回NO的话,走老的司乘同显流程)*/- (BOOL)onSupportPassengerChooseRoute;@end
驾车页相关UI设置请参考demo中的DriveRoute源码部分。
上一篇
下一篇
本篇文章对您是否有帮助?