浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
多路线选择
下载开发文档

算路,选路及上传路线,为了保持司机端和客户端路线一致,该部分接口由司乘同显导航sdk提供。

若乘客端业务需要实现乘客端选择算路路线,乘客端需要集成司乘同显导航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.strategy
naviNodes:@[node1, node2]
delegete:self
userInfo: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)routeIndex
nodesArray:(NSArray<BNRoutePlanNode*>*)nodes
routePlanStrategy:(int)strategy
orderInfo:(BNOrderInfo*)order
extParam:(NSDictionary*)extParam
completion:(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
路线上传
/**
确定使用选中的路线并上传到服务端,用于司机端发起算路导航
@param routeIndex 路线序号,从0开始
@param nodes 算路节点 (算路节点,把算路的算点数据回传)
@param strategy 算路策略,定义见BNRoutePlanStrategyType(把算路的策略回传一下)
@param order 订单信息
@param extParam 额外参数,先预留,目前传nil
@param completion 路线上传结束的回调
*/
__weak typeof(self) weakSelf = self;
[BNaviService_DriveRoute postSelectRoute:self.selectIndex nodesArray:self.nodes routePlanStrategy:self.strategy orderInfo:[OrderSettingViewController getSharedOrder] extParam:nil completion:^(NSDictionary *jsonString, NSError *error) {
if (!error)
{
[weakSelf showAlertWithTitle:@"成功" withContent:@"上传成功"];
}
else
{
[weakSelf showAlertWithTitle:@"失败" withContent:[NSString stringWithFormat:@"%@",[error description]]];
}
}];
司机端对应相关接口

司机端在BNShareLocationProtocol.h新增以下两个接口:

(1)司乘同显模块所需要的数据回调

/**
司乘同显模块所需要的数据回调
*/
@property (weak, nonatomic) id<BNShareLocationDataSource>dataSource;

(2)新增BNShareLocationDataSource协议,可以实现关闭乘客端选路需求

@protocol BNShareLocationDataSource<NSObject>
@optional
/**
是否使用乘客端选择的路线,可选,不实现这个回调默认是NO
@return 是否支持乘客端选路(返回YES的话,司机端会在送乘客阶段尝试拉取相关的路线数据,返回NO的话,走老的司乘同显流程)
*/
- (BOOL)onSupportPassengerChooseRoute;
@end

上一篇

历史轨迹查询

下一篇

相关错误码

本篇文章对您是否有帮助?