Dea*_*Man 15 android google-maps-android-api-2
我想删除以前添加的折线并在更改位置时重新绘制新的折线.我试过了两个
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);
}
}
Run Code Online (Sandbox Code Playgroud)
Raw*_*awa 37
要删除折线,您只需使用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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18440 次 |
| 最近记录: |