| | |
| | | import com.baidu.mapapi.search.route.WalkingRouteResult; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class BaiduUtils { |
| | | public static void initRouteLine(LatLng start,LatLng end,Callback callback){ |
| | | public static void initRouteLine(LatLng start, LatLng end, List<LatLng> center, Callback callback){ |
| | | RoutePlanSearch mSearch = RoutePlanSearch.newInstance(); |
| | | OnGetRoutePlanResultListener listener = new OnGetRoutePlanResultListener(){ |
| | | @Override |
| | |
| | | @Override |
| | | public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) { |
| | | //驾车 |
| | | if (drivingRouteResult.getRouteLines().size()>0){ |
| | | if (drivingRouteResult.getRouteLines()!=null&&drivingRouteResult.getRouteLines().size()>0){ |
| | | DrivingRouteLine drivingRouteLine = drivingRouteResult.getRouteLines().get(0); |
| | | ArrayList<LatLng> latLngs = new ArrayList<>(); |
| | | for (int i=0;i<drivingRouteLine.getAllStep().size();i++){ |
| | |
| | | mSearch.setOnGetRoutePlanResultListener(listener); |
| | | PlanNode stNode = PlanNode.withLocation(start); |
| | | PlanNode enNode = PlanNode.withLocation(end); |
| | | mSearch.drivingSearch((new DrivingRoutePlanOption()) |
| | | List<PlanNode>centers = new ArrayList<PlanNode>(); |
| | | DrivingRoutePlanOption drivingRoutePlanOption = new DrivingRoutePlanOption(); |
| | | drivingRoutePlanOption |
| | | .from(stNode) |
| | | .to(enNode)); |
| | | .to(enNode); |
| | | if (center!=null&¢er.size()!=0){ |
| | | for (LatLng item:center){ |
| | | centers.add( PlanNode.withLocation(item)); |
| | | } |
| | | drivingRoutePlanOption.passBy(centers); |
| | | } |
| | | mSearch.drivingSearch(drivingRoutePlanOption); |
| | | } |
| | | |
| | | public interface Callback{ |