|
@@ -7,7 +7,9 @@ import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
@@ -18,33 +20,67 @@ 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.PathPlanningStrategy;
|
|
|
+import com.amap.api.navi.model.AMapCalcRouteResult;
|
|
|
+import com.amap.api.navi.model.AMapLaneInfo;
|
|
|
+import com.amap.api.navi.model.AMapModelCross;
|
|
|
+import com.amap.api.navi.model.AMapNaviCameraInfo;
|
|
|
+import com.amap.api.navi.model.AMapNaviCross;
|
|
|
+import com.amap.api.navi.model.AMapNaviLocation;
|
|
|
+import com.amap.api.navi.model.AMapNaviPath;
|
|
|
+import com.amap.api.navi.model.AMapNaviRouteNotifyData;
|
|
|
+import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
|
|
|
+import com.amap.api.navi.model.AMapServiceAreaInfo;
|
|
|
+import com.amap.api.navi.model.AimLessModeCongestionInfo;
|
|
|
+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.model.PositionBean;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by shihuiyun
|
|
|
* on 2020/10/15
|
|
|
*/
|
|
|
-public class PolylineActivity extends AppCompatActivity {
|
|
|
+public class PolylineActivity extends AppCompatActivity {
|
|
|
private AMap aMap;
|
|
|
private MapView mapView;
|
|
|
+
|
|
|
+ private AMap aMapTwo;
|
|
|
+ private AMap aMapThree;
|
|
|
+ private MapView mapTwo;
|
|
|
+ private MapView mapThree;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private ImageView imgBack;
|
|
|
private TextView tvStart;
|
|
|
private TextView tvEnd;
|
|
|
private GeocodeSearch geocoderSearch;
|
|
|
-
|
|
|
+ private LinearLayout llBottom;
|
|
|
+ private QMUIRoundButton butOne;
|
|
|
+ private QMUIRoundButton butTwo;
|
|
|
+ private QMUIRoundButton butThree;
|
|
|
private List<LatLng> list;
|
|
|
private List<PositionBean> item;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
StatusBarCompat.setStatusBarColor(this, Color.parseColor("#00ffffff"));
|
|
@@ -55,20 +91,319 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
item = new Gson().fromJson(getIntent().getStringExtra("item"), new TypeToken<List<PositionBean>>() {
|
|
|
}.getType());
|
|
|
|
|
|
- list = showListLat(item);
|
|
|
+
|
|
|
imgBack = findViewById(R.id.img_back);
|
|
|
tvStart = findViewById(R.id.tv_start);
|
|
|
tvEnd = findViewById(R.id.tv_end);
|
|
|
+ llBottom = findViewById(R.id.ll_bottom);
|
|
|
+
|
|
|
+ butOne = findViewById(R.id.but_one);
|
|
|
+ butTwo = findViewById(R.id.but_two);
|
|
|
+ butThree = findViewById(R.id.but_three);
|
|
|
tvStart.setText(item.get(0).position);
|
|
|
tvEnd.setText(item.get(item.size()-1).position);
|
|
|
+
|
|
|
+
|
|
|
imgBack.setOnClickListener(v -> {
|
|
|
finish();
|
|
|
});
|
|
|
|
|
|
mapView = (MapView) findViewById(R.id.map);
|
|
|
+ mapTwo = findViewById(R.id.map_two);
|
|
|
+ mapThree = findViewById(R.id.map_three);
|
|
|
mapView.onCreate(savedInstanceState);// 此方法必须重写
|
|
|
- init();
|
|
|
+ mapTwo.onCreate(savedInstanceState);// 此方法必须重写
|
|
|
+ mapThree.onCreate(savedInstanceState);// 此方法必须重写
|
|
|
+
|
|
|
+
|
|
|
+ butOne.setOnClickListener(view -> {
|
|
|
+ Toast.makeText(this,"切换路线一",Toast.LENGTH_SHORT).show();
|
|
|
+
|
|
|
+ mapView.setVisibility(View.VISIBLE);
|
|
|
+ mapTwo.setVisibility(View.GONE);
|
|
|
+ mapThree.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ butTwo.setOnClickListener(view -> {
|
|
|
+ Toast.makeText(this,"切换路线二",Toast.LENGTH_SHORT).show();
|
|
|
+ mapTwo.setVisibility(View.VISIBLE);
|
|
|
+ mapThree.setVisibility(View.GONE);
|
|
|
+ mapView.setVisibility(View.GONE);
|
|
|
+ });
|
|
|
+ butThree.setOnClickListener(view -> {
|
|
|
+ Toast.makeText(this,"切换路线三",Toast.LENGTH_SHORT).show();
|
|
|
+
|
|
|
+ mapTwo.setVisibility(View.GONE);
|
|
|
+ mapThree.setVisibility(View.VISIBLE);
|
|
|
+ mapView.setVisibility(View.GONE);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ getRoute();
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //获取路线 多条 三条或者一条
|
|
|
+ protected List<NaviLatLng> navOne = new ArrayList<NaviLatLng>();
|
|
|
+ protected List<NaviLatLng> navTwo = new ArrayList<NaviLatLng>();
|
|
|
+ protected List<NaviLatLng> navThree = new ArrayList<NaviLatLng>();
|
|
|
+
|
|
|
+ public void setShow(){
|
|
|
+
|
|
|
+
|
|
|
+ if(navOne.size()>0){
|
|
|
+ llBottom.setVisibility(View.VISIBLE);
|
|
|
+ butOne.setVisibility(View.VISIBLE);
|
|
|
+ list= getshowList(navOne);
|
|
|
+ init();
|
|
|
+
|
|
|
+ }
|
|
|
+ if(navTwo.size()>0){
|
|
|
+ butTwo.setVisibility(View.VISIBLE);
|
|
|
+ list= getshowList(navTwo);
|
|
|
+ initTwo();
|
|
|
+ }
|
|
|
+ if(navThree.size()>0){
|
|
|
+ butThree.setVisibility(View.VISIBLE);
|
|
|
+ list= getshowList(navThree);
|
|
|
+ initThree();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void getRoute(){
|
|
|
+
|
|
|
+ // 获取导航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.calculateDriveRoute(startList, endList, null,
|
|
|
+ PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT);
|
|
|
+
|
|
|
+
|
|
|
+ mAMapNavi.addAMapNaviListener(new AMapNaviListener() {
|
|
|
+ @Override
|
|
|
+ public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
|
|
|
+
|
|
|
+ // 获取路线数据对象
|
|
|
+ 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++;
|
|
|
+ }
|
|
|
+
|
|
|
+ setShow();
|
|
|
+
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onInitNaviFailure() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onInitNaviSuccess() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStartNavi(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTrafficStatusUpdate() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetNavigationText(int i, String s) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetNavigationText(String s) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onEndEmulatorNavi() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onArriveDestination() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCalculateRouteFailure(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReCalculateRouteForYaw() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReCalculateRouteForTrafficJam() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onArrivedWayPoint(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGpsOpenStatus(boolean b) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNaviInfoUpdate(NaviInfo naviInfo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showCross(AMapNaviCross aMapNaviCross) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void hideCross() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showModeCross(AMapModelCross aMapModelCross) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void hideModeCross() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void hideLaneInfo() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCalculateRouteSuccess(int[] ints) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void notifyParallelRoad(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPlayRing(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCalculateRouteFailure(AMapCalcRouteResult aMapCalcRouteResult) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGpsSignalWeak(boolean b) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 初始化AMap对象
|
|
|
*/
|
|
@@ -117,6 +452,100 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
.icon(BitmapDescriptorFactory.fromView(markerEndView)));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void initTwo() {
|
|
|
+ if (aMapTwo == null) {
|
|
|
+ aMapTwo = mapTwo.getMap();
|
|
|
+ setUpMapTwo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ 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 initThree() {
|
|
|
+ if (aMapThree == null) {
|
|
|
+ aMapThree = mapThree.getMap();
|
|
|
+ setUpMapThree();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setUpMapThree() {
|
|
|
+
|
|
|
+ //起点位置和 地图界面大小控制
|
|
|
+ aMapThree.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(0), 7));
|
|
|
+ aMapThree.setMapTextZIndex(2);
|
|
|
+ // 绘制一条带有纹理的直线
|
|
|
+ aMapThree.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);
|
|
|
+ aMapThree.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));
|
|
|
+ aMapThree.addMarker(new MarkerOptions()
|
|
|
+ .position(AMapUtil.convertToLatLng(latLonPointEnd))
|
|
|
+ .icon(BitmapDescriptorFactory.fromView(markerEndView)));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 方法必须重写
|
|
|
*/
|
|
@@ -169,6 +598,18 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public List<LatLng> getshowList( List<NaviLatLng> list){
|
|
|
+
|
|
|
+ List<LatLng> points = new ArrayList<LatLng>();
|
|
|
+
|
|
|
+ for(NaviLatLng ss:list){
|
|
|
+ points.add(new LatLng(ss.getLatitude(), ss.getLongitude()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return points;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|