AI
产品服务
解决方案
文档与支持
定价
更新时间: 2026/03/23 17:19
驾车路线规划
下载开发文档
1. 算路偏好

导航SDK提供8种算路偏好,对应RoutePlanPreference常量。

常量名说明

ROUTE_PLAN_PREFERENCE_DEFAULT

默认,智能推荐

ROUTE_PLAN_PREFERENCE_NOHIGHWAY

少走高速

ROUTE_PLAN_PREFERENCE_NOTOLL

少收费

ROUTE_PLAN_PREFERENCE_AVOID_TRAFFIC_JAM

躲避拥堵

ROUTE_PLAN_PREFERENCE_DISTANCE_FIRST

距离最短,距离优先

ROUTE_PLAN_PREFERENCE_TIME_FIRST

时间最短,时间优先

ROUTE_PLAN_PREFERENCE_ROAD_FIRST

大路优先,高速优先

ROUTE_PLAN_PREFERENCE_ECONOMIC_ROUTE

省钱路线(货车专用)

2、经纬度算路
List<BNRoutePlanNode> list = new ArrayList<>();
BNRoutePlanNode startNode = new BNRoutePlanNode.Builder()
.longitude(116.397609)
.latitude(39.908560)
.build()
BNRoutePlanNode endNode = new BNRoutePlanNode.Builder()
.longitude(116.306333)
.latitude(40.041690)
.build()
list.add(startNode);
list.add(endNode);
BaiduNaviManagerFactory.getRoutePlanManager().routePlan(
list,
IBNRoutePlanManager.RoutePlanPreference.ROUTE_PLAN_PREFERENCE_DEFAULT,
bundle, handler);
3. 途经点算路
List<BNRoutePlanNode> list = new ArrayList<>();
BNRoutePlanNode startNode = new BNRoutePlanNode.Builder()
.longitude(116.397609)
.latitude(39.908560)
.build();
BNRoutePlanNode viaNode = new BNRoutePlanNode.Builder()
.longitude(116.386333)
.latitude(40.042690)
.build()
BNRoutePlanNode endNode = new BNRoutePlanNode.Builder()
.longitude(116.306333)
.latitude(40.041690)
.build();
list.add(startNode);
list.add(viaNode);
list.add(endNode);
BaiduNaviManagerFactory.getRoutePlanManager().routePlan(
list,
IBNRoutePlanManager.RoutePlanPreference.ROUTE_PLAN_PREFERENCE_DEFAULT,
bundle, handler);

可通过setViaPointCount来设置最大途径点的个数(支持4~18个),如下:

BaiduNaviManagerFactory.getCommonSettingManager().setViaPointCount(10)
4、设置车辆信息
// 驾车车牌设置
BaiduNaviManagerFactory.getCommonSettingManager().setCarNum("沪FTP939",IBNOuterSettingParams.CarPowerType.Normal);
5、处理结果

当路线规划成功时,会通过算路时传入的Handler 分发消息回调

private Handler handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_START:
Toast.makeText(DemoMainActivity.this, "算路开始", Toast.LENGTH_SHORT).show();
break;
case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_SUCCESS:
Toast.makeText(DemoMainActivity.this, "算路成功", Toast.LENGTH_SHORT).show();
break;
case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_FAILED:
Toast.makeText(DemoMainActivity.this.getApplicationContext(),
"算路失败", Toast.LENGTH_SHORT).show();
break;
case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_TO_NAVI:
Toast.makeText(DemoMainActivity.this.getApplicationContext(),
"算路成功准备进入导航", Toast.LENGTH_SHORT).show();
break;
}
}
};

上一篇

高级功能

下一篇

新能源路线规划

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