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

路线结果页可以把路线规划的信息进行展示,整个路线结果页除了底图外,其他的上层UI都是可以自定义的,开发者可以根据路线信息进行自定义开发。路线结果页相关的接口和回调在BNDriveRouteProtocol.h头文件中。

result.png
接口

路线结果页对外暴露的接口在BNDriveRouteProtocol中,具体的接口如下:

@protocol BNDriveRouteProtocol <NSObject>
/**
路线结果页面相关事件回调的delegate
*/
@property (nonatomic, weak) id<BNDriveRouteManagerDelegate> delegate;
/**
全览路线
@param margin 需要显示的路线范围的margin
@param animated 全览是否需要动画
*/
- (void)showRouteViewAll:(BNMargin)margin animated:(BOOL)animated;
/**
选中路线,调用该接口后,同时会高亮该路线
@param routeIndex 路线序号(从0开始)
*/
- (void)selectRouteAtIndex:(NSUInteger)routeIndex;
/**
驾车路线页即将显示,在viewWillAppear中调用
@param parentView mapView的父view
*/
- (void)viewWillAppear:(UIView*)parentView;
/**
驾车路线页即将消失,在viewWillDisAppear中调用
@param parentView mapView的父view
*/
- (void)viewWillDisAppear:(UIView*)parentView;
/*
打开定位,驾车页算路成功后需要打开定位才能显示车标
*/
- (void)startUpdateLocation;
/*
关闭定位
*/
- (void)stopUpdateLocation;
/*
获取当前路线信息
@return 当前路线信息 包含城市信息(cityname,citycode)
*/
- (BNCarRouteModel *)getCurrentCarRouteData;
/**
销毁BNDriveRouteManager相关资源
*/
- (void)destory;
@end
回调

路线结果页相关的回调如下:

@protocol BNDriveRouteManagerDelegate <NSObject>
/**
用户在地图上点击了某条路线(如果需要高亮该路线,要调用selectRouteAtIndex:接口)
@param routeIndex 路线序号(从0开始)
*/
- (void)onHandleTouchRouteAtIndex:(NSUInteger)routeIndex;
/**
回调车点
@param positionInfo 车点信息
*/
- (void)onHandleUpdateCurrentCarPositionInfo:(NSDictionary *)positionInfo;
@end
使用说明

下面介绍如何自定义路线结果页,进入和退出导航需要调用的接口。详细可以参考demo工程中的DrivePageViewController类的实现。

1. 把导航SDK的MapView实例添加到视图控制器中

在视图控制器的viewWillAppear:和viewWillDisappear:中添加底图,代码如下:

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[BNaviService_DriveRoute viewWillAppear:self.view];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[BNaviService_DriveRoute viewWillDisAppear:self.view];
}
2. 路线规划

发起路线规划,代码如下:

- (void)startRoutePlan {
[BNaviService_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:self.nodes time:nil delegete:self userInfo:@{BNaviTripTypeKey: @(self.naviTye)}];
}
3. 算路成功后的处理

算路成功后,可以进行以下操作,开发者可以根据自己的实际情况进行处理:

(1)选择路线:默认选择序号为0的路线,开发者也可以选择其他的路线,选中的路线会高亮。

(2)路线全览:把路线全览到屏幕的某个区域。

(3)获取路线数据,根据路线数据刷新UI,算路成功后的数据结构参考BNCarRouteModel类。

(4)开启定位,开启后才能显示车标。

具体代码如下:

- (void)routePlanDidFinished:(NSDictionary*)userInfo {
//获取路线数据
BNCarRouteModel *route = userInfo[BNDriveRouteDataKey];
NSInteger routeCount = route.carRoutes.count;
//路线序号从0开始,这里选择序号为1的路线
NSInteger selectIndex = 1 < routeCount ? 1 : 0;
//选择某条路线
[BNaviService_DriveRoute selectRouteAtIndex:selectIndex];
//把路线全览到某个区域
[BNaviService_DriveRoute showRouteViewAll:margin animated:YES];
//刷新UI
[self updateUI];
// 算路成功后需要打开定位才能显示车标
[BNaviService_DriveRoute startUpdateLocation];
}
4. 处理路线选择回调

用户点击底图上的某条路线后,选中的路线会高亮,同时对外有如下回调,开发者可以在该回调中处理路线高亮后的UI刷新。

/**
用户在地图上点击了某条路线(如果需要高亮该路线,要调用selectRouteAtIndex:接口)
@param routeIndex 路线序号(从0开始)
*/
- (void)onHandleTouchRouteAtIndex:(NSUInteger)routeIndex;
5. 进入专业导航

从驾车页进入导航页前需要先停止驾车页的定位监听,然后通过发起导航跳转到导航页。

- (void)enterNaviPage {
[BNaviService_DriveRoute stopUpdateLocation];
[BNaviService_UI showPage:BNaviUI_NormalNavi delegate:self extParams:@{BNaviUI_NormalNavi_TypeKey: @(self.naviTye)}];
}
6. 从专业导航退出回到路线结果页

可以在以下回调中处理从专业导航中退出,回到路线结果页。具体操作包括:

(1)设置路线全览

(2)重新开启定位

(3)获取当前的路线数据,刷新UI

具体代码如下:

/**
* 即将退出UI的回调
*
* @param pageType UI类型
* @param extraInfo 额外参数
*/
- (void)willExitPage:(BNaviUIType)pageType extraInfo:(NSDictionary*)extraInfo {
//路线全量
[BNaviService_DriveRoute showRouteViewAll:margin animated:YES];
//开启定位
[BNaviService_DriveRoute startUpdateLocation];
//获取路线数据,刷新UI
BNCarRouteModel *route = [BNaviService_DriveRoute getCurrentCarRouteData];
[self updateUI];
}
限行信息获取

算路完成后,可以获取到路线的限行信息,限行信息在黄条数据结构里,BNCarRouteData.h头文件中,具体如下:

/// 单个小黄条数据结构
@interface BNYellowTipsInfo: NSObject
/// 小黄条标题
@property (nonatomic, copy) NSString *title;
@end

上一篇

摩托车路线规划

下一篇

算路准确性

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