Переглянути джерело

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	gaode/src/main/java/com/quansu/gaode/activity/PolylineActivity.java
石慧云 4 роки тому
батько
коміт
ec9a941a55

+ 127 - 156
gaode/src/main/java/com/quansu/gaode/activity/PolylineActivity.java

@@ -11,20 +11,20 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.Toast;
 
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
-
 import com.amap.api.maps.AMap;
 import com.amap.api.maps.CameraUpdateFactory;
 import com.amap.api.maps.MapView;
+import com.amap.api.maps.model.BitmapDescriptor;
 import com.amap.api.maps.model.BitmapDescriptorFactory;
 import com.amap.api.maps.model.LatLng;
 import com.amap.api.maps.model.MarkerOptions;
 import com.amap.api.maps.model.PolylineOptions;
 import com.amap.api.navi.AMapNavi;
 import com.amap.api.navi.AMapNaviListener;
+import com.amap.api.navi.enums.NaviType;
 import com.amap.api.navi.enums.PathPlanningStrategy;
 import com.amap.api.navi.model.AMapCalcRouteResult;
+import com.amap.api.navi.model.AMapCarInfo;
 import com.amap.api.navi.model.AMapLaneInfo;
 import com.amap.api.navi.model.AMapModelCross;
 import com.amap.api.navi.model.AMapNaviCameraInfo;
@@ -39,19 +39,24 @@ import com.amap.api.navi.model.AimLessModeStat;
 import com.amap.api.navi.model.NaviInfo;
 import com.amap.api.navi.model.NaviLatLng;
 import com.amap.api.services.core.LatLonPoint;
-import com.amap.api.services.geocoder.GeocodeSearch;
 import com.githang.statusbar.StatusBarCompat;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
 import com.quansu.gaode.R;
 import com.quansu.gaode.utils.AMapUtil;
+import com.ysnows.base.dialog.QMUIProgressDialog;
 import com.ysnows.base.model.PositionBean;
 
+import org.jetbrains.annotations.NotNull;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+
 /**
  * Created by shihuiyun
  * on 2020/10/15
@@ -69,7 +74,6 @@ public class PolylineActivity extends AppCompatActivity {
     private ImageView imgBack;
     private TextView tvStart;
     private TextView tvEnd;
-    private GeocodeSearch geocoderSearch;
     private LinearLayout llBottom;
     private QMUIRoundButton butOne;
     private QMUIRoundButton butTwo;
@@ -88,10 +92,6 @@ public class PolylineActivity extends AppCompatActivity {
         item = new Gson().fromJson(getIntent().getStringExtra("item"), new TypeToken<List<PositionBean>>() {
         }.getType());
 
-
-        Log.e("-shy-", "item=: " + item.size());
-
-
         imgBack = findViewById(R.id.img_back);
         tvStart = findViewById(R.id.tv_start);
         tvEnd = findViewById(R.id.tv_end);
@@ -140,6 +140,10 @@ public class PolylineActivity extends AppCompatActivity {
         });
 
 
+        aMap = mapView.getMap();
+        aMapTwo = mapTwo.getMap();
+        aMapThree = mapThree.getMap();
+
         getRoute();
 
     }
@@ -152,91 +156,90 @@ public class PolylineActivity extends AppCompatActivity {
 
     public void setShow() {
 
-
         if (navOne.size() > 0) {
             llBottom.setVisibility(View.VISIBLE);
             butOne.setVisibility(View.VISIBLE);
             list = getshowList(navOne);
-            init();
-
+            setUpMap(aMap);
         }
         if (navTwo.size() > 0) {
             butTwo.setVisibility(View.VISIBLE);
             list = getshowList(navTwo);
-            initTwo();
+            setUpMap(aMapTwo);
         }
+
         if (navThree.size() > 0) {
             butThree.setVisibility(View.VISIBLE);
             list = getshowList(navThree);
-            initThree();
+            setUpMap(aMapThree);
         }
 
-        Log.e("-shy-", "navOne=" + navOne.size());
-        Log.e("-shy-", "navTwo=" + navTwo.size());
-        Log.e("-shy-", "navThree=" + navThree.size());
         if (navOne.size() == 0 && navTwo.size() == 0 && navThree.size() == 0) {
             list = showListLat(item);
-            init();
+            setUpMap(aMap);
         }
 
     }
 
 
     public void getRoute() {
+        // 构建车辆信息
+        AMapCarInfo carInfo = new AMapCarInfo();
+        carInfo.setCarNumber("鲁Q13C2G");   //设置车牌号
+//        carInfo.setCarType("1");             //设置车辆类型,0:小车; 1:货车. 默认0(小车).
+//        carInfo.setVehicleAxis("6");         //设置货车的轴数,mCarType = 1时候生效,取值[0-255],默认为2
+//        carInfo.setVehicleHeight("3.56");    //设置货车的高度,单位:米,mCarType = 1时候生效,取值[0-25.5],默认1.6米
+//        carInfo.setVehicleLength("7.3");     //设置货车的最大长度,单位:米,mCarType = 1时候生效,取值[0-25],默认6米
+//        carInfo.setVehicleWidth("2.5");      //设置货车的最大宽度,单位:米,mCarType = 1时候生效,取值[0-25.5],默认2.5米
+//        carInfo.setVehicleSize("4");         //设置货车的大小,1-微型货车 2-轻型/小型货车 3-中型货车 4-重型货车,默认为2
+//        carInfo.setVehicleLoad("25.99");     //设置货车的总重,即车重+核定载重,单位:吨,mCarType = 1时候生效,取值[0-6553.5]
+//        carInfo.setVehicleWeight("20");      //设置货车的核定载重,单位:吨,mCarType = 1时候生效,取值[0-6553.5]
+//        carInfo.setRestriction(true);        //设置是否躲避车辆限行,true代表躲避车辆限行,false代表不躲避车辆限行,默认为true
+//        carInfo.setVehicleLoadSwitch(true);   //设置货车重量是否参与算路,true-重量会参与算路;false-重量不会参与算路。默认为false
 
         // 获取导航Manager
         AMapNavi mAMapNavi = AMapNavi.getInstance(this);
-        // 起点信息
-        List<NaviLatLng> startList = new ArrayList<NaviLatLng>();
-        startList.add(new NaviLatLng(Double.parseDouble(item.get(0).latitude), Double.parseDouble(item.get(0).longitude)));
-        // 终点信息
-        List<NaviLatLng> endList = new ArrayList<NaviLatLng>();
-        endList.add(new NaviLatLng(Double.parseDouble(item.get(item.size() - 1).latitude), Double.parseDouble(item.get(item.size() - 1).longitude)));
 
+        mAMapNavi.setCarInfo(carInfo);
+
+//         起点信息
+        List<NaviLatLng> startList = initStartPoint(item.get(0));
+//         终点信息
+        List<NaviLatLng> endList = initEndPoint(item.get(item.size() - 1));
         //中间停靠点
-        List<NaviLatLng> centerList = null;
-        if (item.size() > 2) {
-            centerList = new ArrayList<NaviLatLng>();
-            int i = 0;
-            for (PositionBean ss : item) {
-                if (i > 0 || i < item.size() - 1) {
-                    if (!TextUtils.isEmpty(ss.latitude) && !TextUtils.isEmpty(ss.longitude)) {
-                        centerList.add(new NaviLatLng(Double.parseDouble(ss.latitude), Double.parseDouble(ss.longitude)));
-                    }
-                }
-                i++;
-            }
-        }
+        List<NaviLatLng> centerList = initCenterPointList();
         // 经纬度算路
         mAMapNavi.calculateDriveRoute(startList, endList, centerList,
                 PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT);
 
+        QMUIProgressDialog qmuiProgressDialog = new QMUIProgressDialog();
+        qmuiProgressDialog.show(this,"正在规划路线...");
+
+
+        addCenterListMarker(centerList);
 
         mAMapNavi.addAMapNaviListener(new AMapNaviListener() {
             @Override
             public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
-
-                try {
-
-                    // 获取路线数据对象
-                    HashMap<Integer, AMapNaviPath> naviPaths = mAMapNavi.getNaviPaths();
-                    // 绘制显示路径 遍历值
-                    int i = 0;
-                    for (AMapNaviPath value : naviPaths.values()) {
-                        if (i == 0) {
-                            navOne.addAll(value.getCoordList());
-                        }
-                        if (i == 1) {
-                            navTwo.addAll(value.getCoordList());
-
-                        }
-                        if (i == 2) {
-                            navThree.addAll(value.getCoordList());
-                        }
-                        i++;
+                qmuiProgressDialog.dismiss();
+                // 获取路线数据对象
+                HashMap<Integer, AMapNaviPath> naviPaths = mAMapNavi.getNaviPaths();
+                // 绘制显示路径 遍历值
+                int i = 0;
+                AMapNavi.getInstance(PolylineActivity.this).startNavi(NaviType.GPS);
+
+                for (AMapNaviPath value : naviPaths.values()) {
+                    if (i == 0) {
+                        navOne.addAll(value.getCoordList());
                     }
-                } catch (Exception e) {
+                    if (i == 1) {
+                        navTwo.addAll(value.getCoordList());
 
+                    }
+                    if (i == 2) {
+                        navThree.addAll(value.getCoordList());
+                    }
+                    i++;
                 }
 
                 setShow();
@@ -421,125 +424,95 @@ public class PolylineActivity extends AppCompatActivity {
         });
     }
 
-
-    /**
-     * 初始化AMap对象
-     */
-    private void init() {
-        if (aMap == null) {
-            aMap = mapView.getMap();
-            geocoderSearch = new GeocodeSearch(this);
-            setUpMap();
+    private List<NaviLatLng> initCenterPointList() {
+        List<NaviLatLng> centerList = new ArrayList<NaviLatLng>();
+        if (item.size() > 2) {
+            int i = 0;
+            for (PositionBean ss : item) {
+                if (i > 0 || i < item.size() - 1) {
+                    if (!TextUtils.isEmpty(ss.latitude) && !TextUtils.isEmpty(ss.longitude)) {
+                        centerList.add(new NaviLatLng(Double.parseDouble(ss.latitude), Double.parseDouble(ss.longitude)));
+                    }
+                }
+                i++;
+            }
         }
+        mockCenterList(centerList);
+        return centerList;
     }
 
-    private void setUpMap() {
-
-        //起点位置和  地图界面大小控制
-        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(0), 7));
-        aMap.setMapTextZIndex(2);
-        // 绘制一条带有纹理的直线
-        aMap.addPolyline((new PolylineOptions())
-                //手动数据测试
-                //.add(new LatLng(26.57, 106.71),new LatLng(26.14,105.55),new LatLng(26.58, 104.82), new LatLng(30.67, 104.06))
-                //集合数据
-                .addAll(list)
-                //线的宽度
-                .width(30).setDottedLine(true).geodesic(true)
-                //颜色
-                .color(Color.argb(255, 255, 20, 147)));
-
-
-        if (TextUtils.isEmpty(item.get(0).latitude) || TextUtils.isEmpty(item.get(item.size() - 1).latitude)) {
-            return;
-        }
-        LatLonPoint latLonPoint = new LatLonPoint(Double.parseDouble(item.get(0).latitude), Double.parseDouble(item.get(0).longitude));
-
-        //起点图标
-        View markerView = LayoutInflater.from(this).inflate(R.layout.gaode_start_marker, mapView, false);
-        aMap.addMarker(new MarkerOptions()
-                .position(AMapUtil.convertToLatLng(latLonPoint))
-                .icon(BitmapDescriptorFactory.fromView(markerView)));
-
-        //终点坐标
-        View markerEndView = LayoutInflater.from(this).inflate(R.layout.gaode_end_marker, mapView, false);
-
-        LatLonPoint latLonPointEnd = new LatLonPoint(Double.parseDouble(item.get(item.size() - 1).latitude), Double.parseDouble(item.get(item.size() - 1).longitude));
-        aMap.addMarker(new MarkerOptions()
-                .position(AMapUtil.convertToLatLng(latLonPointEnd))
-                .icon(BitmapDescriptorFactory.fromView(markerEndView)));
+    @NotNull
+    private List<NaviLatLng> initEndPoint(PositionBean end) {
+        List<NaviLatLng> list = new ArrayList<NaviLatLng>();
+        list.add(new NaviLatLng(Double.parseDouble(end.latitude), Double.parseDouble(end.longitude)));
+        return list;
     }
 
-
-    private void initTwo() {
-        if (aMapTwo == null) {
-            aMapTwo = mapTwo.getMap();
-            setUpMapTwo();
-        }
+    @NotNull
+    private List<NaviLatLng> initStartPoint(PositionBean start) {
+        List<NaviLatLng> list = new ArrayList<NaviLatLng>();
+        list.add(new NaviLatLng(Double.parseDouble(start.latitude), Double.parseDouble(start.longitude)));
+        return list;
     }
 
-    private void setUpMapTwo() {
-
-        //起点位置和  地图界面大小控制
-        aMapTwo.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(0), 7));
-        aMapTwo.setMapTextZIndex(2);
-        // 绘制一条带有纹理的直线
-        aMapTwo.addPolyline((new PolylineOptions())
-                //手动数据测试
-                //.add(new LatLng(26.57, 106.71),new LatLng(26.14,105.55),new LatLng(26.58, 104.82), new LatLng(30.67, 104.06))
-                //集合数据
-                .addAll(list)
-                //线的宽度
-                .width(30).setDottedLine(true).geodesic(true)
-                //颜色
-                .color(Color.argb(255, 255, 20, 147)));
-
-
-        if (TextUtils.isEmpty(item.get(0).latitude) || TextUtils.isEmpty(item.get(item.size() - 1).latitude)) {
-            return;
+    /**
+     * 添加中间点的图标
+     *
+     * @param centerList
+     */
+    private void addCenterListMarker(List<NaviLatLng> centerList) {
+        BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.ic_vehicle);
+
+        for (int i = 0; i < centerList.size(); i++) {
+            NaviLatLng naviLatLng = centerList.get(i);
+            //起点图标
+            aMap.addMarker(new MarkerOptions()
+                    .position(new LatLng(naviLatLng.getLatitude(), naviLatLng.getLongitude()))
+                    .icon(icon));
         }
-        LatLonPoint latLonPoint = new LatLonPoint(Double.parseDouble(item.get(0).latitude), Double.parseDouble(item.get(0).longitude));
-
-        //起点图标
-        View markerView = LayoutInflater.from(this).inflate(R.layout.gaode_start_marker, mapView, false);
-        aMapTwo.addMarker(new MarkerOptions()
-                .position(AMapUtil.convertToLatLng(latLonPoint))
-                .icon(BitmapDescriptorFactory.fromView(markerView)));
-
-        //终点坐标
-        View markerEndView = LayoutInflater.from(this).inflate(R.layout.gaode_end_marker, mapView, false);
+    }
 
-        LatLonPoint latLonPointEnd = new LatLonPoint(Double.parseDouble(item.get(item.size() - 1).latitude), Double.parseDouble(item.get(item.size() - 1).longitude));
-        aMapTwo.addMarker(new MarkerOptions()
-                .position(AMapUtil.convertToLatLng(latLonPointEnd))
-                .icon(BitmapDescriptorFactory.fromView(markerEndView)));
+    private void mockCenterList(List<NaviLatLng> centerList) {
+        centerList.add(new NaviLatLng(Double.parseDouble("41.706654"), Double.parseDouble("123.475442")));
+        centerList.add(new NaviLatLng(Double.parseDouble("40.999653"), Double.parseDouble("117.956253")));
+        centerList.add(new NaviLatLng(Double.parseDouble("39.846721"), Double.parseDouble("116.447675")));
+        centerList.add(new NaviLatLng(Double.parseDouble("38.486194"), Double.parseDouble("106.237175")));
+        centerList.add(new NaviLatLng(Double.parseDouble("36.090479"), Double.parseDouble("103.808732")));
+        centerList.add(new NaviLatLng(Double.parseDouble("36.090479"), Double.parseDouble("103.808732")));
+        centerList.add(new NaviLatLng(Double.parseDouble("34.689417"), Double.parseDouble("113.68808")));
+        centerList.add(new NaviLatLng(Double.parseDouble("32.112732"), Double.parseDouble("118.802529")));
+        centerList.add(new NaviLatLng(Double.parseDouble("30.262288"), Double.parseDouble("120.145532")));
+        centerList.add(new NaviLatLng(Double.parseDouble("28.261974"), Double.parseDouble("112.933791")));
+        centerList.add(new NaviLatLng(Double.parseDouble("26.670167"), Double.parseDouble("106.623518")));
+        centerList.add(new NaviLatLng(Double.parseDouble("22.874771"), Double.parseDouble("108.389659")));
+        centerList.add(new NaviLatLng(Double.parseDouble("24.518109"), Double.parseDouble("118.103432")));
+        centerList.add(new NaviLatLng(Double.parseDouble("26.073548"), Double.parseDouble("119.280859")));
     }
 
 
-    private void initThree() {
-        if (aMapThree == null) {
-            aMapThree = mapThree.getMap();
-            setUpMapThree();
-        }
-    }
+    private void setUpMap(AMap aMap) {
 
-    private void setUpMapThree() {
 
         //起点位置和  地图界面大小控制
-        aMapThree.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(0), 7));
-        aMapThree.setMapTextZIndex(2);
+        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(0), 7));
+        aMap.setMapTextZIndex(2);
         // 绘制一条带有纹理的直线
-        aMapThree.addPolyline((new PolylineOptions())
+        aMap.addPolyline((new PolylineOptions())
                 //手动数据测试
                 //.add(new LatLng(26.57, 106.71),new LatLng(26.14,105.55),new LatLng(26.58, 104.82), new LatLng(30.67, 104.06))
                 //集合数据
                 .addAll(list)
                 //线的宽度
-                .width(30).setDottedLine(true).geodesic(true)
+//                .setUseTexture(true)
+//                .setCustomTexture(BitmapDescriptorFactory.defaultMarker())
+                .width(20).setDottedLine(false).geodesic(true)
                 //颜色
-                .color(Color.argb(255, 255, 20, 147)));
+                .color(Color.argb(255, 96, 208, 117)));
+
 
 
+//        View dotView = LayoutInflater.from(this).inflate(R.layout.gaode_start_marker, mapView, false);
+
         if (TextUtils.isEmpty(item.get(0).latitude) || TextUtils.isEmpty(item.get(item.size() - 1).latitude)) {
             return;
         }
@@ -547,7 +520,7 @@ public class PolylineActivity extends AppCompatActivity {
 
         //起点图标
         View markerView = LayoutInflater.from(this).inflate(R.layout.gaode_start_marker, mapView, false);
-        aMapThree.addMarker(new MarkerOptions()
+        aMap.addMarker(new MarkerOptions()
                 .position(AMapUtil.convertToLatLng(latLonPoint))
                 .icon(BitmapDescriptorFactory.fromView(markerView)));
 
@@ -555,7 +528,7 @@ public class PolylineActivity extends AppCompatActivity {
         View markerEndView = LayoutInflater.from(this).inflate(R.layout.gaode_end_marker, mapView, false);
 
         LatLonPoint latLonPointEnd = new LatLonPoint(Double.parseDouble(item.get(item.size() - 1).latitude), Double.parseDouble(item.get(item.size() - 1).longitude));
-        aMapThree.addMarker(new MarkerOptions()
+        aMap.addMarker(new MarkerOptions()
                 .position(AMapUtil.convertToLatLng(latLonPointEnd))
                 .icon(BitmapDescriptorFactory.fromView(markerEndView)));
     }
@@ -601,8 +574,6 @@ public class PolylineActivity extends AppCompatActivity {
      *经纬度集合
      */
     private List<LatLng> showListLat(List<PositionBean> item) {
-
-
         List<LatLng> points = new ArrayList<LatLng>();
 
         for (PositionBean ss : item) {

BIN
gaode/src/main/res/drawable-xxhdpi/end.png


BIN
gaode/src/main/res/drawable-xxhdpi/ic_vehicle.png


BIN
gaode/src/main/res/drawable-xxhdpi/start.png


+ 18 - 0
gaode/src/main/res/layout/gaode_center_marker.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/qmui_config_color_blue" >
+
+        <ImageView
+            android:layout_width="35dp"
+            android:layout_height="35dp"
+            android:src="@drawable/ic_arrow_back_black_24dp" />
+
+    </LinearLayout >
+
+</LinearLayout >