Muhammad Umar
Muhammad Umar

Reputation: 11782

Removing PolyLine from googlemaps v2

I am trying to remove a polyline from GoogleMaps V2

On Marker Drag, i want to change the polyline drawn from previous marker to the dragged marker,

Here is the class for marker drag, but in it how can i remove the polyline?

 mMap.setOnMarkerDragListener(new OnMarkerDragListener() 
        {

            public void onMarkerDragStart(Marker marker) 
            {
            }

            public void onMarkerDragEnd(Marker marker) 
            {
mMap.addPolyLine(///)
}

Upvotes: 8

Views: 7163

Answers (2)

Simon
Simon

Reputation: 2733

If you want to remove a single Polyline from the map, you will have to add it in a slightly different way:

List<Polyline> lines = new ArrayList<Polyline>();

lines.add(googleMap.addPolyline(new PolylineOptions()
        .addAll(lineCoordinates)
        .width(width)
        .color(color))); //the line will appear on the map here

lines.get(0).remove(); // the line should disappear

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006584

You can call clear() to remove all markers, polylines, and polygons from your GoogleMap. Or, you can call remove() on the Marker, Polyline, or Polygon to remove an individual element from your map.

Upvotes: 23

Related Questions