|
@@ -11,19 +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;
|
|
@@ -38,24 +39,29 @@ 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
|
|
|
*/
|
|
|
-public class PolylineActivity extends AppCompatActivity {
|
|
|
+public class PolylineActivity extends AppCompatActivity {
|
|
|
private AMap aMap;
|
|
|
private MapView mapView;
|
|
|
|
|
@@ -65,13 +71,9 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
private MapView mapThree;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
private ImageView imgBack;
|
|
|
private TextView tvStart;
|
|
|
private TextView tvEnd;
|
|
|
- private GeocodeSearch geocoderSearch;
|
|
|
private LinearLayout llBottom;
|
|
|
private QMUIRoundButton butOne;
|
|
|
private QMUIRoundButton butTwo;
|
|
@@ -80,7 +82,6 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
private List<PositionBean> item;
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
StatusBarCompat.setStatusBarColor(this, Color.parseColor("#00ffffff"));
|
|
@@ -88,13 +89,9 @@ 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() );
|
|
|
-
|
|
|
-
|
|
|
imgBack = findViewById(R.id.img_back);
|
|
|
tvStart = findViewById(R.id.tv_start);
|
|
|
tvEnd = findViewById(R.id.tv_end);
|
|
@@ -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);
|
|
@@ -143,97 +140,103 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
});
|
|
|
|
|
|
|
|
|
+ aMap = mapView.getMap();
|
|
|
+ aMapTwo = mapTwo.getMap();
|
|
|
+ aMapThree = mapThree.getMap();
|
|
|
+
|
|
|
getRoute();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//获取路线 多条 三条或者一条
|
|
|
- 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);
|
|
|
- init();
|
|
|
-
|
|
|
+ list = getshowList(navOne);
|
|
|
+ setUpMap(aMap);
|
|
|
}
|
|
|
- if(navTwo.size()>0){
|
|
|
+ if (navTwo.size() > 0) {
|
|
|
butTwo.setVisibility(View.VISIBLE);
|
|
|
- list= getshowList(navTwo);
|
|
|
- initTwo();
|
|
|
+ list = getshowList(navTwo);
|
|
|
+ setUpMap(aMapTwo);
|
|
|
}
|
|
|
- if(navThree.size()>0){
|
|
|
+
|
|
|
+ if (navThree.size() > 0) {
|
|
|
butThree.setVisibility(View.VISIBLE);
|
|
|
- list= getshowList(navThree);
|
|
|
- initThree();
|
|
|
+ list = getshowList(navThree);
|
|
|
+ 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){
|
|
|
+ if (navOne.size() == 0 && navTwo.size() == 0 && navThree.size() == 0) {
|
|
|
list = showListLat(item);
|
|
|
- init();
|
|
|
+ setUpMap(aMap);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void getRoute(){
|
|
|
+ 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) {
|
|
|
-
|
|
|
+ qmuiProgressDialog.dismiss();
|
|
|
// 获取路线数据对象
|
|
|
- HashMap<Integer, AMapNaviPath> naviPaths =mAMapNavi.getNaviPaths();
|
|
|
+ HashMap<Integer, AMapNaviPath> naviPaths = mAMapNavi.getNaviPaths();
|
|
|
// 绘制显示路径 遍历值
|
|
|
- int i=0;
|
|
|
+ int i = 0;
|
|
|
+ AMapNavi.getInstance(PolylineActivity.this).startNavi(NaviType.GPS);
|
|
|
+
|
|
|
for (AMapNaviPath value : naviPaths.values()) {
|
|
|
- if(i==0){
|
|
|
+ if (i == 0) {
|
|
|
navOne.addAll(value.getCoordList());
|
|
|
}
|
|
|
- if(i==1){
|
|
|
+ if (i == 1) {
|
|
|
navTwo.addAll(value.getCoordList());
|
|
|
|
|
|
}
|
|
|
- if(i==2){
|
|
|
+ if (i == 2) {
|
|
|
navThree.addAll(value.getCoordList());
|
|
|
}
|
|
|
i++;
|
|
@@ -242,6 +245,7 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
setShow();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void onInitNaviFailure() {
|
|
|
|
|
@@ -420,150 +424,115 @@ 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)){
|
|
|
+ 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);
|
|
|
- aMapThree.addMarker(new MarkerOptions()
|
|
|
+ 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));
|
|
|
- aMapThree.addMarker(new MarkerOptions()
|
|
|
+ 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)));
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 方法必须重写
|
|
|
*/
|
|
@@ -581,6 +550,7 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
super.onPause();
|
|
|
mapView.onPause();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 方法必须重写
|
|
|
*/
|
|
@@ -598,17 +568,16 @@ 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 +585,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 +598,4 @@ public class PolylineActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|