示例中心
功能在线体验
控制台

高德 开发 iOS 导航SDK 开发指南 出行路线规划 货车路线规划

更新时间:2018年03月09日

基本介绍

从导航SDK v6.0.0版本开始,全面支持货车导航功能,包括组件和导航功能。其中主要区别于驾车的部分就是在货车的路径规划策略中,会将货车特有的限高、车型等信息加入路径规划策略进行计算。

特别注意:货车路径规划目前默认给出的是测试配额,每日调用次数上限100次,QPS上限1,如果您有更高配额要求,请通过工单系统提交商务合作类工单进行沟通。

使用说明

第 1 步,初始化

1)初始化导航的起点和终点坐标(为了方便展示路线,特定固定了起点和终点坐标)

- (void)initProperties
{
    self.startPoint = [AMapNaviPoint locationWithLatitude:39.99 longitude:116.47];
    self.endPoint   = [AMapNaviPoint locationWithLatitude:39.90 longitude:116.32];
}
let startPoint = AMapNaviPoint.location(withLatitude: 39.993135, longitude: 116.474175)!
let endPoint = AMapNaviPoint.location(withLatitude: 39.908791, longitude: 116.321257)!

2)初始化 MAMapView。

- (void)initMapView
{
    if (self.mapView == nil)
    {
        self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, kRoutePlanInfoViewHeight,
                                                                   self.view.bounds.size.width,
                                                                   self.view.bounds.size.height - kRoutePlanInfoViewHeight)];
        [self.mapView setDelegate:self];
        [self.view addSubview:self.mapView];
    }
}
func initMapView() {
    mapView = MAMapView(frame: CGRect(x: 0, y: routePlanInfoViewHeight, width: view.bounds.width, height: view.bounds.height - routePlanInfoViewHeight))
    mapView.delegate = self
    view.addSubview(mapView)
}

3)初始化 AMapNaviDriveManager。

- (void)initDriveManager
{
       //请在 dealloc 函数中执行 [AMapNaviDriveManager destroyInstance] 来销毁单例
       [[AMapNaviDriveManager sharedInstance] setDelegate:self];
}
func initDriveManager() {
        //请在 deinit 函数中执行 AMapNaviDriveManager.destroyInstance() 来销毁单例
        AMapNaviDriveManager.sharedInstance().delegate = self
}

第 2 步,计算驾车规划路线

在计算路径规划前,设置车辆信息,当type为1时为货车:

 //设置车辆信息
AMapNaviVehicleInfo *info = [[AMapNaviVehicleInfo alloc] init];
info.vehicleId = "京N66Y66"; //设置车牌号
info.type = 1;              //设置车辆类型,0:小车; 1:货车. 默认0(小车).
info.size = 4;              //设置货车的类型(大小)
info.width = 3;             //设置货车的宽度,范围:(0,5],单位:米
info.height = 3.9;          //设置货车的高度,范围:(0,10],单位:米
info.length = 15;           //设置货车的长度,范围:(0,25],单位:米
info.weight = 50;           //设置货车的总重量,范围:(0,100]
info.load = 45;             //设置货车的核定载重,范围:(0,100],核定载重应小于总重
info.axisNums = 6;          //设置货车的轴数(用来计算过路费及限重)
[[AMapNaviDriveManager sharedInstance] setVehicleInfo:info];

[[AMapNaviDriveManager sharedInstance] calculateDriveRouteWithStartPoints:@[self.startPoint]
                                            endPoints:@[self.endPoint]
                                            wayPoints:nil
                                      drivingStrategy:17];
//设置车辆信息
let info = AMapNaviVehicleInfo.init()
info.vehicleId = "京N66Y66"; //设置车牌号
info.type = 1;              //设置车辆类型,0:小车; 1:货车. 默认0(小车).
info.size = 4;              //设置货车的类型(大小)
info.width = 3;             //设置货车的宽度,范围:(0,5],单位:米
info.height = 3.9;          //设置货车的高度,范围:(0,10],单位:米
info.length = 15;           //设置货车的长度,范围:(0,25],单位:米
info.weight = 50;           //设置货车的总重量,范围:(0,100]
info.load = 45;             //设置货车的核定载重,范围:(0,100],核定载重应小于总重量
info.axisNums = 6;          //设置货车的轴数(用来计算过路费及限重)
let success = AMapNaviDriveManager.sharedInstance().setVehicleInfo(info)

AMapNaviDriveManager.sharedInstance().calculateDriveRoute(
withStart: [startPoint],
end: [endPoint],
wayPoints: nil, 
drivingStrategy: 17) 


第 3 步,处理结果

当驾车路线规划成功时,会进 driveManagerOnCalculateRouteSuccess 回调,在该回调函数中,可以进行规划路线显示,同时返回了专门针对货车的限行信息。也可以直接开启导航。

说明:1)通过 AMapNaviDriveManager 的 naviRoutes 获取规划路线的列表,线路详细信息请参考 AMapNaviRoute 类。2)若进行线路展示,可通过 AMapNaviRoute 的 routeCoordinates 属性,可获取导航路线的所有形状点,然后通过在 MAMapView 上绘制线进行线路展示。3)若想开启导航,请参考在地图上导航

- (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager
{
    NSLog(@"onCalculateRouteSuccess");
    //禁行信息if (driveManager.naviRoute.forbiddenInfo.count) {
    for (AMapNaviRouteForbiddenInfo *info in driveManager.naviRoute.forbiddenInfo) {
            NSLog(@"禁行信息:类型:%ld,车型:%@,道路名:%@,禁行时间段:%@,经纬度:%@",(long)info.type,info.vehicleType,info.roadName,info.timeDescription,info.coordinate);
    }
}

    //限行设施
    if (driveManager.naviRoute.roadFacilityInfo.count) {
        for (AMapNaviRoadFacilityInfo *info in driveManager.naviRoute.roadFacilityInfo) {
            if (info.type == AMapNaviRoadFacilityTypeTruckHeightLimit || info.type == AMapNaviRoadFacilityTypeTruckWidthLimit || info.type == AMapNaviRoadFacilityTypeTruckWeightLimit) {
                NSLog(@"限行信息:类型:%ld,道路名:%@,经纬度:%@",(long)info.type,info.roadName,info.coordinate);
            }
        }
    }
}
func driveManager(onCalculateRouteSuccess driveManager: AMapNaviDriveManager) {
   NSLog("CalculateRouteSuccess")
    //禁行信息
    if ((driveManager.naviRoute?.forbiddenInfo.count) != 0) {
    for info in (driveManager.naviRoute?.forbiddenInfo)! {
             NSLog("禁行信息:类型: \(info.type),车型: \(info.vehicleType),道路名: \(info.roadName),禁行时间段: \(info.timeDescription),经纬度: \(info.coordinate)")
            }
     }

    //限行设施
    if ((driveManager.naviRoute?.roadFacilityInfo.count) != 0) {
            for info in (driveManager.naviRoute?.roadFacilityInfo)! {
                NSLog("限行信息:类型: \(info.type.rawValue),道路名: \(info.roadName),经纬度: \(info.coordinate)")
                }
            }

     }


第 4 步,当退出页面的时候,销毁AMapNaviDriveManager单例

- (void)dealloc
{
    [[AMapNaviDriveManager sharedInstance] stopNavi];
    [[AMapNaviDriveManager sharedInstance] removeDataRepresentative:self.driveView];
    [[AMapNaviDriveManager sharedInstance] setDelegate:nil];
    
    BOOL success = [AMapNaviDriveManager destroyInstance];
    NSLog(@"单例是否销毁成功 : %d",success);
    
}
deinit {
    AMapNaviDriveManager.sharedInstance().stopNavi()
    AMapNaviDriveManager.sharedInstance().removeDataRepresentative(driveView)
    AMapNaviDriveManager.sharedInstance().delegate = nil
        
    let success = AMapNaviDriveManager.destroyInstance()
    NSLog("单例是否销毁成功 : \(success)")
        
}


示例中心 功能
在线体验
常见问题