开发 HarmonyOS NEXT 导航SDK 开发指南 路线规划 骑行电动车路径规划

骑行电动车路径规划 最后更新时间: 2026年05月29日

基本介绍

从导航SDK v11.1.0版本开始,全面支持骑行电动车路径规划和导航功能。使用骑行电动车路径规划和导航功能, AMapNavi接口 

中提供了多种路径规划的方式供您使用。

特别注意:骑行电动车路径规划是收费接口,您如果申请试用或者正式应用都请通过工单系统提交商务合作类工单进行沟通,否则默认是无法算路成功的。

说明:

  • 注意:路径规划功能需要联网使用。
  • 起终点信息可通过多种方式获取,如:使用坐标拾取器查询您需要的点的坐标;还可以通过搜索 SDK 中的 poi  搜索查询兴趣点,作为起终点。
  • 提供三种骑行路线规划的方法,如下表所示:

方法名

参数说明

返回值说明

方法效果

calculateEleBikeRouteLatLngWithoutStart(to: INaviLatLng | null, wayPoints?: ArrayList<NaviLatLng>): boolean;

to:终点坐标;

wayPoints : 途径点;

BOOL,表示规划路径所需条件和参数校验是否成功,不代表算路是否成功。

终点为经纬度的无起点骑行电动车路径规划。(内部取当前定位点作为起点)

calculateEleBikeRouteLatLng(from: INaviLatLng | null, to: INaviLatLng | null, wayPoints?: ArrayList<NaviLatLng>): boolean;

from:起点坐标;

to:终点坐标;

wayPoints : 途径点;

BOOL,表示规划路径所需条件和参数校验是否成功,不代表算路是否成功。

起终点为经纬度的骑行电动车路径规划。

calculateEleBikeRoutePoi(fromPoi: INaviPoi | null, toPoi: INaviPoi | null, strategy: TravelStrategy, wayPoints?: ArrayList): Promise<boolean>;

fromPoi:起点POI;

toPoi:终点POI;

strategy:路径的计算策略;

BOOL,表示规划路径所需条件和参数校验是否成功,不代表算路是否成功。

起终点为POI的骑行电动车路径规划。(起点可为空,内部取当前定位点作为起点)

推荐使用 calculateEleBikeRoutePoi(fromPoi: INaviPoi | null, toPoi: INaviPoi | null, strategy: TravelStrategy, wayPoints?: ArrayList): Promise<boolean>;方法进行路径规划,SDK内部会根据 poiId 自动补全其他信息,从而规划出更合理的路线,有效减少绕路的出现。

使用说明

1. 经纬度算路

传入起、终点的经纬度信息来规划路线。

骑行电动车无起点算路示例代码:

  const appKey = "您的appKey";
  const naviInstance: IAMapNavi = AMapNaviFactory.getAMapNaviInstance(getContext().getApplicationContext(), appKey);
  // 设置终点
  let end : NaviLatLng  = new NaviLatLng(39.917834, 116.397036);
  // 经纬度算路
  naviInstance!.calculateEleBikeRouteLatLngWithoutStart(this.endLatlng, this.wayList);

骑行电动车算路示例代码:

  const appKey = "您的appKey";
  const naviInstance: IAMapNavi = AMapNaviFactory.getAMapNaviInstance(getContext().getApplicationContext(), appKey);
  // 设置起点
  let startLatlng : NaviLatLng = new NaviLatLng(39.993308, 116.473199);
  // 设置终点
  let end : NaviLatLng  = new NaviLatLng(39.917834, 116.397036);
  // 经纬度算路
  naviInstance!.calculateEleBikeRouteLatLng(this.startLatlng, this.endLatlng, this.wayList);

2. POI算路

传入起、终点的POI信息来规划骑行电动车路线。

2.1 单路径规划

示例代码:

  const appKey = "您的appKey";
  const naviInstance: IAMapNavi = AMapNaviFactory.getAMapNaviInstance(getContext().getApplicationContext(), appKey);
  // 构造起点POI
  const start = new NaviPoi("善各庄地铁", new NaviLatLng(40.027021,116.478391), null);
  // 构造终点POI
  const end = new NaviPoi("天安门广场", new NaviLatLng(39.907033, 116.39754), null);
  // 途径点
  const poiList = new ArrayList<NaviPoi>();
  // 进行骑行电动车算路
  naviInstance!.calculateEleBikeRoutePoi(start, end, PathPlanningStrategy.TRAVEL_SINGLE_DEFAULT ,poiList)

2.2 多路径规划

示例代码:

  const appKey = "您的appKey";
  const naviInstance: IAMapNavi = AMapNaviFactory.getAMapNaviInstance(getContext().getApplicationContext(), appKey);
  // 构造起点POI
  const start = new NaviPoi("善各庄地铁", new NaviLatLng(40.027021,116.478391), null);
  // 构造终点POI
  const end = new NaviPoi("天安门广场", new NaviLatLng(39.907033, 116.39754), null);
  // 途径点
  const poiList = new ArrayList<NaviPoi>();
  // 进行骑行电动车算路
  naviInstance!.calculateEleBikeRoutePoi(start, end, PathPlanningStrategy.TRAVEL_MULTIPLE_DEFAULT ,poiList)

3. 处理结果

当路线规划成功后,会触发 AMapNaviListener 的 onCalculateRouteSuccess 回调,在该回调函数中,你可以获取路线对象,进行规划路线的显示:

 this.naviInstance?.addAMapNaviListener({
      onCalculateRouteSuccess: (routeResult: IAMapCalcRouteResult | null) => {
        // 获取路线数据对象
        const paths: HashMap<number, AMapNaviPath> | null = this.naviInstance!.getNaviPaths();
        // 绘制显示路径
        ...ß
        
      }
    })

也可以直接开启骑行电动车导航:

 this.naviInstance?.addAMapNaviListener({
      onCalculateRouteSuccess: (routeResult: IAMapCalcRouteResult | null) => {
        // 开启导航
        this.naviInstance!.startNavi(NaviType.GPS)
      }
    })

如果路线规划失败,则会触发 AMapNaviListener 的 onCalculateRouteFailure 回调,可以在此回调中来执行相应处理逻辑。

返回顶部 示例中心 常见问题 智能客服 公众号
二维码