示例代码:
BNRoutePlanNode sNode = new BNRoutePlanNode.Builder().latitude(40.05087).longitude(116.30142).name("百度大厦").description("百度大厦").coordinateType(CoordinateType.GCJ02).build();BNRoutePlanNode eNode = new BNRoutePlanNode.Builder().latitude(39.90882).longitude(116.39750).name("北京天安门").description("北京天安门").coordinateType(CoordinateType.GCJ02).build();List<BNRoutePlanNode> list = new ArrayList<>();list.add(sNode);list.add(eNode);BaiduNaviManagerFactory.getRoutePlanManager().routeplan(list, IBNRoutePlanManager.RoutePlanPreference.ROUTE_PLAN_PREFERENCE_DEFAULT, null, new Handler(Looper.getMainLooper()) {@Overridepublic void handleMessage(Message msg) {switch (msg.what) {case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_START:Toast.makeText(DemoMainActivity.this.gtApplicationContext(),"算路开始", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_SUCCESS:Toast.makeText(DemoMainActivity.this.getApplicationContext(),"算路成功", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_FAILED:Toast.makeText(DemoMainActivity.this.getApplicationContext(),"算路失败", Toast.LENGTH_SHORT).show();break;default:// nothingbreak;}}});
路线规划成功后,就可以使用驾车页,驾车页依赖App的页面生命周期,开发时,只需要将百度导航SDK驾车页生命周期接口挂接到对应页面的生命周期接口即可,App页面既可以是Activity,也可以是Fragment等。生命周期相关方法在BaiduNaviManagerFactory.getRouteResultManager()中:
/*** 在Activity的onCreate() 或者 Fragment的onCreateView()中调用*/void onCreate(Context context);/*** 在Activity的onResume() 或者 Fragment的onResume() 中调用*/void onResume();/*** 在Activity的onPause() 或者 Fragment的onPause() 中调用*/void onPause();/*** 在Activity的onDestroy() 或者 Fragment的onDestroy() 中调用*/void onDestroy();
调用方法以OnCreate为例:
@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {// 获取路线规划UIView view = BaiduNaviManagerFactory.getRouteResultManager().onCreate(getActivity());return view;}
路线规划成功后通常情况下会出现3条路线,该接口可监听某条路线是否被点击,如果被点击可调用BaiduNaviManagerFactory.getRouteGuideManager().selectRoute(index)高亮并选中该条路线。
/*** 路线点击事件监听*/void setRouteClickedListener(IRouteClickedListener listener);/*** 路线点击事件*/interface IRouteClickedListener {/*** 点击了第几条* @param index*/void routeClicked(int index);}
BaiduNaviManagerFactory.getRouteResultManager().fullView();
无需重新算路,直接跳转新页面调用专业导航生命周期即可,可参考demo。
// 返回true,代表可以跳转至专业导航BaiduNaviManagerFactory.getRouteResultManager().startNavi();}
/*** 获取3Tab信息和路线详情*/Bundle getRouteInfo();
返回的bundle中数据如下,具体使用方法可以参考demo中DemoRouteResultFragment类。
Bundle bundle = BaiduNaviManagerFactory.getRouteResultManager().getRouteInfo();if (bundle == null) {return;}// 3Tab信息mRoutePlanItems = bundle.getParcelableArrayList(BNaviCommonParams.BNRouteInfoKey.INFO_TAB);// 每条路线的详细信息mRouteDetails = bundle.getBundle(BNaviCommonParams.BNRouteInfoKey.INFO_ROUTE_DETAIL);// 每条路线的坐标点Bundle pointList = bundle.getBundle(BNaviCommonParams.BNRouteInfoKey.INFO_ROUTE_POINT);if (pointList != null) {ArrayList<BNPoint> bnPoints0 = pointList.getParcelableArrayList("0");ArrayList<BNPoint> bnPoints1 = pointList.getParcelableArrayList("1");ArrayList<BNPoint> bnPoints2 = pointList.getParcelableArrayList("2");}
驾车页设置BaiduNaviManagerFactory.getRouteResultSettingManager()接口如下:
/*** 设置全览路线边距* @param left* @param top* @param right* @param bottom*/void setRouteMargin(int left, int top, int right, int bottom);
上一篇
下一篇
本篇文章对您是否有帮助?