|
@@ -13,6 +13,7 @@ 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;
|
|
@@ -55,7 +56,7 @@ 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;
|
|
|
|
|
@@ -65,9 +66,6 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
private MapView mapThree;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
private ImageView imgBack;
|
|
|
private TextView tvStart;
|
|
|
private TextView tvEnd;
|
|
@@ -80,7 +78,6 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
private List<PositionBean> item;
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
StatusBarCompat.setStatusBarColor(this, Color.parseColor("#00ffffff"));
|
|
@@ -88,11 +85,11 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.map_layout);
|
|
|
|
|
|
- item = new Gson().fromJson(getIntent().getStringExtra("item"), new TypeToken<List<PositionBean>>() {
|
|
|
+ item = new Gson().fromJson(getIntent().getStringExtra("item"), new TypeToken<List<PositionBean>>() {
|
|
|
}.getType());
|
|
|
|
|
|
|
|
|
- Log.e("-shy-", "item=: "+item.size() );
|
|
|
+ Log.e("-shy-", "item=: " + item.size());
|
|
|
|
|
|
|
|
|
imgBack = findViewById(R.id.img_back);
|
|
@@ -104,7 +101,7 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
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);
|
|
|
+ tvEnd.setText(item.get(item.size() - 1).position);
|
|
|
|
|
|
|
|
|
imgBack.setOnClickListener(v -> {
|
|
@@ -120,7 +117,7 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
butOne.setOnClickListener(view -> {
|
|
|
- Toast.makeText(this,"切换路线一",Toast.LENGTH_SHORT).show();
|
|
|
+ Toast.makeText(this, "切换路线一", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
mapView.setVisibility(View.VISIBLE);
|
|
|
mapTwo.setVisibility(View.GONE);
|
|
@@ -129,13 +126,13 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
});
|
|
|
|
|
|
butTwo.setOnClickListener(view -> {
|
|
|
- Toast.makeText(this,"切换路线二",Toast.LENGTH_SHORT).show();
|
|
|
+ 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();
|
|
|
+ Toast.makeText(this, "切换路线三", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
mapTwo.setVisibility(View.GONE);
|
|
|
mapThree.setVisibility(View.VISIBLE);
|
|
@@ -148,38 +145,36 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//获取路线 多条 三条或者一条
|
|
|
- protected List<NaviLatLng> navOne = new ArrayList<NaviLatLng>();
|
|
|
- protected List<NaviLatLng> navTwo = new ArrayList<NaviLatLng>();
|
|
|
- protected List<NaviLatLng> navThree = new ArrayList<NaviLatLng>();
|
|
|
+ protected List<NaviLatLng> navOne = new ArrayList<NaviLatLng>();
|
|
|
+ protected List<NaviLatLng> navTwo = new ArrayList<NaviLatLng>();
|
|
|
+ protected List<NaviLatLng> navThree = new ArrayList<NaviLatLng>();
|
|
|
|
|
|
- public void setShow(){
|
|
|
+ public void setShow() {
|
|
|
|
|
|
|
|
|
- if(navOne.size()>0){
|
|
|
+ if (navOne.size() > 0) {
|
|
|
llBottom.setVisibility(View.VISIBLE);
|
|
|
butOne.setVisibility(View.VISIBLE);
|
|
|
- list= getshowList(navOne);
|
|
|
+ list = getshowList(navOne);
|
|
|
init();
|
|
|
|
|
|
}
|
|
|
- if(navTwo.size()>0){
|
|
|
+ if (navTwo.size() > 0) {
|
|
|
butTwo.setVisibility(View.VISIBLE);
|
|
|
- list= getshowList(navTwo);
|
|
|
+ list = getshowList(navTwo);
|
|
|
initTwo();
|
|
|
}
|
|
|
- if(navThree.size()>0){
|
|
|
+ if (navThree.size() > 0) {
|
|
|
butThree.setVisibility(View.VISIBLE);
|
|
|
- list= getshowList(navThree);
|
|
|
+ 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){
|
|
|
+ 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();
|
|
|
}
|
|
@@ -187,24 +182,24 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void getRoute(){
|
|
|
+ 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)));
|
|
|
+ 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)));
|
|
|
+ endList.add(new NaviLatLng(Double.parseDouble(item.get(item.size() - 1).latitude), Double.parseDouble(item.get(item.size() - 1).longitude)));
|
|
|
|
|
|
//中间停靠点
|
|
|
List<NaviLatLng> centerList = null;
|
|
|
- if(item.size()>2) {
|
|
|
- centerList=new ArrayList<NaviLatLng>();
|
|
|
- int i=0;
|
|
|
+ if (item.size() > 2) {
|
|
|
+ centerList = new ArrayList<NaviLatLng>();
|
|
|
+ int i = 0;
|
|
|
for (PositionBean ss : item) {
|
|
|
- if(i>0||i<item.size()-1) {
|
|
|
+ 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)));
|
|
|
}
|
|
@@ -212,7 +207,7 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
- // 经纬度算路
|
|
|
+ // 经纬度算路
|
|
|
mAMapNavi.calculateDriveRoute(startList, endList, centerList,
|
|
|
PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT);
|
|
|
|
|
@@ -221,27 +216,33 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
@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());
|
|
|
+ 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++;
|
|
|
}
|
|
|
- if(i==1){
|
|
|
- navTwo.addAll(value.getCoordList());
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
- }
|
|
|
- if(i==2){
|
|
|
- navThree.addAll(value.getCoordList());
|
|
|
- }
|
|
|
- i++;
|
|
|
}
|
|
|
|
|
|
setShow();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void onInitNaviFailure() {
|
|
|
|
|
@@ -421,7 +422,6 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 初始化AMap对象
|
|
|
*/
|
|
@@ -447,24 +447,24 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
//线的宽度
|
|
|
.width(30).setDottedLine(true).geodesic(true)
|
|
|
//颜色
|
|
|
- .color(Color.argb(255,255,20,147)));
|
|
|
+ .color(Color.argb(255, 255, 20, 147)));
|
|
|
|
|
|
|
|
|
- if(TextUtils.isEmpty(item.get(0).latitude)||TextUtils.isEmpty(item.get(item.size()-1).latitude)){
|
|
|
+ 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));
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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));
|
|
|
+ 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)));
|
|
@@ -492,24 +492,24 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
//线的宽度
|
|
|
.width(30).setDottedLine(true).geodesic(true)
|
|
|
//颜色
|
|
|
- .color(Color.argb(255,255,20,147)));
|
|
|
+ .color(Color.argb(255, 255, 20, 147)));
|
|
|
|
|
|
|
|
|
- if(TextUtils.isEmpty(item.get(0).latitude)||TextUtils.isEmpty(item.get(item.size()-1).latitude)){
|
|
|
+ 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));
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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));
|
|
|
+ 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)));
|
|
@@ -537,33 +537,30 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
//线的宽度
|
|
|
.width(30).setDottedLine(true).geodesic(true)
|
|
|
//颜色
|
|
|
- .color(Color.argb(255,255,20,147)));
|
|
|
+ .color(Color.argb(255, 255, 20, 147)));
|
|
|
|
|
|
|
|
|
- if(TextUtils.isEmpty(item.get(0).latitude)||TextUtils.isEmpty(item.get(item.size()-1).latitude)){
|
|
|
+ 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));
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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));
|
|
|
+ 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)));
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 方法必须重写
|
|
|
*/
|
|
@@ -581,6 +578,7 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
super.onPause();
|
|
|
mapView.onPause();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 方法必须重写
|
|
|
*/
|
|
@@ -598,17 +596,18 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
super.onDestroy();
|
|
|
mapView.onDestroy();
|
|
|
}
|
|
|
+
|
|
|
/***
|
|
|
*经纬度集合
|
|
|
*/
|
|
|
- private List<LatLng> showListLat(List<PositionBean> item){
|
|
|
+ private List<LatLng> showListLat(List<PositionBean> item) {
|
|
|
|
|
|
|
|
|
List<LatLng> points = new ArrayList<LatLng>();
|
|
|
|
|
|
- for(PositionBean ss:item){
|
|
|
- if(!TextUtils.isEmpty(ss.latitude)&&!TextUtils.isEmpty(ss.longitude)) {
|
|
|
- Log.e("-shy-", "latitude=: "+ss.latitude+"//longitude="+ss.longitude );
|
|
|
+ for (PositionBean ss : item) {
|
|
|
+ if (!TextUtils.isEmpty(ss.latitude) && !TextUtils.isEmpty(ss.longitude)) {
|
|
|
+ Log.e("-shy-", "latitude=: " + ss.latitude + "//longitude=" + ss.longitude);
|
|
|
points.add(new LatLng(Double.parseDouble(ss.latitude), Double.parseDouble(ss.longitude)));
|
|
|
}
|
|
|
}
|
|
@@ -616,11 +615,11 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public List<LatLng> getshowList( List<NaviLatLng> list){
|
|
|
+ public List<LatLng> getshowList(List<NaviLatLng> list) {
|
|
|
|
|
|
List<LatLng> points = new ArrayList<LatLng>();
|
|
|
|
|
|
- for(NaviLatLng ss:list){
|
|
|
+ for (NaviLatLng ss : list) {
|
|
|
points.add(new LatLng(ss.getLatitude(), ss.getLongitude()));
|
|
|
}
|
|
|
|
|
@@ -629,5 +628,4 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|