1.在onCreate之前
BaiduMapHelper.init((MyApplication) getApplicationContext()) 2路径规划
implements OnGetRoutePlanResultListener
mSearch = RoutePlanSearch.newInstance(); mSearch.setOnGetRoutePlanResultListener(this);
mSearch.drivingSearch((new DrivingRoutePlanOption()) .from(passNode).to(enNode));
@Override public void onGetDrivingRouteResult(DrivingRouteResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { //Toast.makeText(OrderGoingActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT).show(); result.getSuggestAddrInfo(); } if (result.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) { // 起终点或途经点地址有岐义,通过以下接口获取建议查询信息 result.getSuggestAddrInfo(); return; } if (result.error == SearchResult.ERRORNO.NO_ERROR) { nodeIndex = -1; if (result.getRouteLines().size() > 0) { route = result.getRouteLines().get(0); DrivingRouteOverlay overlay = new OrderGoingActivity.MyDrivingRouteOverlay(mBaidumap); routeOverlay = overlay; mBaidumap.setOnMarkerClickListener(overlay); overlay.setData(result.getRouteLines().get(0)); overlay.addToMap(); //overlay.zoomToSpan(); // if(order.getStatus()==40) { //} } else { Log.d("route result", "结果数<0"); return; } } } @Override public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) { }
// 定制RouteOverly private class MyDrivingRouteOverlay extends DrivingRouteOverlay { public MyDrivingRouteOverlay(BaiduMap baiduMap) { super(baiduMap); } @Override public BitmapDescriptor getStartMarker() { //if (useDefaultIcon) { // return BitmapDescriptorFactory.fromResource(R.drawable.qi); // } return null; } @Override public BitmapDescriptor getTerminalMarker() { //if (useDefaultIcon) { // return BitmapDescriptorFactory.fromResource(R.drawable.zhong); // } return null; } }