算路,选路及上传路线,为了保持司机端和客户端路线一致,该部分接口由司乘同显导航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*类型数据,结构体定义如下:
@interfacebndriveoneroutedata :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@interfacebndriveroutedata :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源码部分。
上一篇
下一篇
本篇文章对您是否有帮助?