android - 如何在移动时删除从源到当前位置的折线路径
问题描述
我想在移动时删除以前的折线,我正在使用 GoogleDirection 类来绘制折线。请参考下面的代码片段
GoogleDirection.withServerKey(getResources().getString(R.string.google_maps_key))
.from(origin)
.to(destination)
.transportMode(TransportMode.DRIVING)
.alternativeRoute(true)
.execute(this);
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
mMap.clear();
mMap.addMarker(new MarkerOptions().position(destination));
ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
polyline = mMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 3, Color.BLACK));
}
@Override
public void onDirectionFailure(Throwable t) {
Log.e("Direction fail Sorry", " no route found for this location.");
请参考截图,需要根据当前位置更新折线。
解决方案
要删除折线,您应该简单地使用 remove() 方法
//Add line to map
Polyline confirmPathPlotLine= mMap.addPolyline(new PolylineOptions()
.add(new LatLng(location.getLatitude(), location.getLongitude()),
new LatLng(this.destinationLatitude, this.destinationLongitude))
.width(1)
.color(Color.DKGRAY)
//Remove the same line from map
confirmPathPlotLine.remove();
推荐阅读
- r - R中的序列变化编码
- python - “小于”运算符在 Python 中不起作用
- html - 如何在 Vuetify.js 中使文本换行到下一行
- c# - System.Text.Json 序列化 Unicode 字符(如表情符号)的问题
- .net - 为什么为日期类型对象分配一个值不能正确地获得它的值?
- python - 如何生成包含连续数字和字母混合的列表?
- javascript - Three.js中点的局部到全局(反之亦然)矩阵变换
- autodesk-forge - 为什么我的线宽不显示在 2D Forge Viewer 中?
- python - 与其他表达式进行 OR 运算时,Python 正则表达式与组不匹配
- php - MethodNotAllowedHttpException 在另一个类服务中调用 Model::create