2013-03-01 105 views
10

我正在谷歌开发者的网站中添加一个折线选项。删除折线谷歌地图v2的问题android

PolylineOptions rectOptions = new PolylineOptions() 
     .add(new LatLng(37.35, -122.0)) 
     .add(new LatLng(37.45, -122.0)) // North of the previous point, but at the same longitude 
     .add(new LatLng(37.45, -122.2)) // Same latitude, and 30km to the west 
     .add(new LatLng(37.35, -122.2)) // Same longitude, and 16km to the south 
     .add(new LatLng(37.35, -122.0)); // Closes the polyline. 

// Get back the mutable Polyline 
Polyline polyline = myMap.addPolyline(rectOptions); 

我想删除它。但没有rectOptions.remove() 我没有更新谷歌播放服务从我的SDK Google Maps Android API v2, how to remove Polylines from the map? 中提到但我仍然没有它。在从SDK管理器更新之后,我应该多做些什么?我真的需要删除它,而不是为了节省内存而使它不可见,因为我会显示很多次点的路径。

回答

11

要删除Polyline,使用polyline.remove();

+0

所以我想,当你的PolylineOptions X申报;你不能使用remove()。删除仅为Polyline对象定义。所以我使用了这一个 – 2013-03-01 11:02:48

+0

PolylineOptions仅有助于使折线的初始化更容易(对于其他* Options类也是如此)。您需要对折线本身进行折线操作。 – Mokus 2013-03-01 11:32:08

+0

@Mokus我有多边形,我做同样的事情,你发布答案,但不会从地图中删除地图,我如何刷新它? [请参阅文档](https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polygon#remove%28%29) – 2014-01-07 07:26:08

2

你不应该使用PolylineOptions将其删除。

使用PolyLine这样

polyline.remove(); 

Documentation

public void remove() 

Removes this polyline from the map. After a polyline has been removed, the behavior of all its methods is undefined.

+0

是的,我知道了。我改成了Polyline。谢谢Mitesh – 2013-03-01 11:04:27