我正在尝试删除之前添加的多段线,并在位置更改后重新绘制新的多段线。我都试过了
this.routeToDestination.setPoints(pointsToDestination) 和 this.routeToDestination.remove()
但他们都没有工作。
我关注了How to draw a dynamic line (route) with Google Maps Android API v2但无法解决问题
@Override
public void onResume() {
super.onResume();
routeToDestination = mMap.addPolyline(new PolylineOptions()
.add(new LatLng(location.getLatitude(), location.getLongitude()),
new LatLng(this.destinationLatitude, this.destinationLongitude))
.width(1)
.color(Color.DKGRAY)
);
}
@Override
public void onLocationChanged(Location location) {
List<LatLng> pointsToDestination = new ArrayList<LatLng>();
pointsToDestination.add(new LatLng(location.getLatitude(), location.getLongitude()));
pointsToDestination.add(new LatLng(destinationLatitude, destinationLongitude));
this.routeToDestination.setPoints(pointsToDestination);
}
}
最佳答案
要删除折线,您只需使用 API 中所述的 remove() 方法即可。
//Add line to map
Polyline line = 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
line.remove();
关于android - Google Maps Android API v2,如何从 map 中删除折线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15139271/