我正在尝试在位置更改时删除先前添加的折线并重新绘制新的折线。 我尝试了 this.routeToDestination.setPoints(pointsToDestination)和this.routeToDestination.remove() 但都没有起作用。 我遵循了 如何使用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);
}
}