1,画轨迹线
/**
* 画轨迹图
* */
private void DrawLines(){
List<LatLng> mPointList = new ArrayList<>();
mPointList.add(new LatLng(26.57, 106.71));
mPointList.add(new LatLng(26.14,105.55));
mPointList.add(new LatLng(26.58, 104.82));
mPointList.add(new LatLng(27.68, 104.07));
mPointList.add(new LatLng(30.67, 104.06));
for (LatLngpoint : mPointList ){
LogUtil.i("last add :"+point.getLatitude()+ ", "+point.getLongitude());
mPointList.add(new LatLng(point.getLatitude(), point.getLongitude()));
//添加图钉
aMap.addMarker(getMarkerOptions(new LatLng(point.getLatitude(), point.getLongitude())));
}
//将地图移动到定位点
aMap.moveCamera(CameraUpdateFactory.changeLatLng(mPointList.get(0)));
//起点位置和 地图界面大小控制
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mPointList.get(0), 14));
//aMap.setMapTextZIndex(2); // 3D地图的接口
aMap.addPolyline((new PolylineOptions())
//颜色
.color(Color.argb(255,254,52,48))
// 否画虚线
.setDottedLine(false)
//线的宽度
.width(25)
//是否为大地曲线
.geodesic(true)
//手动数据测试
//.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(mPointList));
// clear data
mPointList.clear();
}
2,画纹理线
/**
* 画轨迹图
* */
private void DrawLines(){
List<LatLng> mPointList = new ArrayList<>();
mPointList.add(new LatLng(26.57, 106.71));
mPointList.add(new LatLng(26.14,105.55));
mPointList.add(new LatLng(26.58, 104.82));
mPointList.add(new LatLng(27.68, 104.07));
mPointList.add(new LatLng(30.67, 104.06));
for (LatLng point : mPointList ){
LogUtil.i("last add :"+point.getLatitude()+ ", "+point.getLongitude());
mPointList.add(new LatLng(point.getLatitude(), point.getLongitude()));
//添加图钉
aMap.addMarker(getMarkerOptions(new LatLng(point.getLatitude(), point.getLongitude())));
}
// 添加纹理图片
List<BitmapDescriptor> textureList = new ArrayList<BitmapDescriptor>();
//BitmapDescriptor mRoadArrow = BitmapDescriptorFactory.fromAsset("road_red_arrow");
BitmapDescriptor mRoadArrow = BitmapDescriptorFactory.fromResource(R.drawable.road_red_arrow);
for (int i=1; i< mPointList.size(); i++) {
textureList.add(mRoadArrow);
}
// 添加纹理图片的顺序
List<Integer> textureIndexes = new ArrayList<>();
for (int i=1; i< mPointList.size(); i++) {
// 对应上面 textureList 中的第 (i-1) 个纹理
textureIndexes.add(i-1);
}
//将地图移动到定位点
aMap.moveCamera(CameraUpdateFactory.changeLatLng(mPointList.get(0)));
//起点位置和 地图界面大小控制
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mPointList.get(0), 14));
//aMap.setMapTextZIndex(2); // 3D地图的接口
aMap.addPolyline((new PolylineOptions())
// //颜色
// .color(Color.argb(255,254,52,48))
// // 否画虚线
// .setDottedLine(false)
//线的宽度
.width(25)
// //是否为大地曲线
// .geodesic(true)
//手动数据测试
//.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(mPointList)
// 使用纹理
.setCustomTextureList(textureList)
.setCustomTextureIndex(textureIndexes)
// .setCustomTexture(mRoadArrow)
.setUseTexture(true));
// clear data
mPointList.clear();
textureList.clear();
textureIndexes.clear();
}
3,添加图钉
/**
* 给点增加涂钉
**/
private MarkerOptions getMarkerOptions(LatLng latLng){
//设置图钉选项
MarkerOptions options = new MarkerOptions();
//图标
//options.icon(BitmapDescriptorFactory.fromResource(R.drawable.comm_img_checkbox_full));
//位置
options.position(latLng);
StringBuffer buffer = new StringBuffer();
// buffer.append(amapLocation.getCountry() + "" + amapLocation.getProvince() + "" + amapLocation.getCity() + "" + amapLocation.getDistrict() + "" + amapLocation.getStreet() + "" + amapLocation.getStreetNum());
buffer.append("地点:"+"深圳市南山区XXXXXX");
//标题
options.title(buffer.toString());
//子标题
options.snippet("定位时间:"+"2022-02-22");
//设置多少帧刷新一次图片资源
options.period(60);
return options;
}
|