如何从地图中删除所有多段线

如何从地图中删除所有多段线

本文介绍了如何从地图中删除所有多段线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注





我必须在两个标记之间添加很多多义线,创建一个路径。

其中一个标记是可拖动的,可以说源是可拖动的。



所以,当用户开始拖动标记,必须删除先前绘制的路径,并且必须绘制新源和目标之间的新路径。

我能够绘制新路径,但是我怎样才能擦除前面的路径?



这是如何绘制路径的:

  for(int z = 0; z< list.size() -  1; z ++){
LatLng src = list.get(z);
LatLng dest = list.get(z + 1);
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(src.latitude,src.longitude),
new LatLng(dest.latitude,dest.longitude))
.width(2).color(Color.RED).geodesic(true));
}

我可以得到的一个解决方案是

清除所有折线,标记等



但是一旦我开始拖动,标记就会被清除,因此在地图上不可见:(

p>

谢谢

解决方案

地图:

  Polyline polyline = this.mMap.addPolyline(new PolylineOptions().....); 

然后当您想删除它时:

<$ p $如果你有很多的多段线,那么你可以使用它来创建一个多段线,只需将它们添加到列表中即可:

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

(...)
{
polylines.add(this.mMap.addPolyline(new PolylineOption S()....));
}

当您想要删除时:

pre $ (折线:多段线)
{
line.remove();
}

polylines.clear();

关键是保留对Polyline对象的引用并在每个对象上调用.remove()。

Following

How to draw a path between two markers

I had to add lot of polylines between two markers, to make a path.

One of the markers is draggable, lets say source is draggable.

So, when user starts dragging the marker, the path previously drawn must be erased and a new path between new source and destination must be draw.

I am able to draw the new path, but how can i erase the previous path?

This is how the path is drawn:

    for (int z = 0; z < list.size() - 1; z++) {
        LatLng src = list.get(z);
        LatLng dest = list.get(z + 1);
        Polyline line = map.addPolyline(new PolylineOptions()
                .add(new LatLng(src.latitude, src.longitude),
                        new LatLng(dest.latitude, dest.longitude))
                .width(2).color(Color.RED).geodesic(true));
    }

One solution i can get is

To clear all the polylines, markers etc.. and add the markers again, then drawn the path.

But as soon as I start dragging, the marker is cleared, hence not visible on the map :(

Thank You

解决方案

Keep track of the Polyline as you add it to the map:

Polyline polyline = this.mMap.addPolyline(new PolylineOptions().....);

Then when you want to remove it:

polyline.remove();

If you have lots of Polylines, just add them to a List as they are put on the map:

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

for(....)
{
    polylines.add(this.mMap.addPolyline(new PolylineOptions()....));
}

And when you want to delete:

for(Polyline line : polylines)
{
    line.remove();
}

polylines.clear();

The key is to keep a reference to the Polyline objects and call .remove() on each one.

这篇关于如何从地图中删除所有多段线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:14