导航SDK提供8种算路偏好,对应RoutePlanPreference常量。
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);
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)
// 驾车车牌设置BaiduNaviManagerFactory.getCommonSettingManager().setCarNum("沪FTP939",IBNOuterSettingParams.CarPowerType.Normal);
当路线规划成功时,会通过算路时传入的Handler 分发消息回调
private Handler handler = new Handler(Looper.getMainLooper()) {@Overridepublic 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;}}};
上一篇
下一篇
本篇文章对您是否有帮助?