更新时间:2026/11/30 15:37
1. 算路偏好
导航SDK提供8种算路偏好,对应RoutePlanPreference常量。
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; } }};本篇文章对您是否有帮助?