【问题标题】:How to clear Google map v2 except few markers?除了少数标记外,如何清除 Google map v2?
【发布时间】:2015-02-13 02:44:26
【问题描述】:

假设我在地图上有 100 个标记,我想要的是当我应用 GoogleMap.clear(); 清除地图时,它会清除地图上的所有其他标记,除了 2 个标记和它们之间的 1 条折线一条路径。

 marker1 = GoogleMap .addMarker(new MarkerOptions().position(latLng1).title(A));

 marker2 = GoogleMap .addMarker(new MarkerOptions().position(latLng2).title(B));

 line = GoogleMap.addPolyline(options1);

我不想清除这三个。我想要这个,所以用户不必经历眨眼。

【问题讨论】:

  • 我认为唯一的方法是删除除您要显示的标记之外的所有标记。
  • 将所有标记存储在 avriable... 然后根据您的要求删除.. 检查stackoverflow.com/questions/27457828/…

标签: android google-maps google-maps-markers google-polyline


【解决方案1】:

除了某些东西之外,没有办法清除所有东西。但是,您可以保留对要清除的任何标记的引用并在它们上循环。

ArrayList<Marker> markersToClear = new ArrayList<Marker>();

marker1 = GoogleMap.addMarker(new MarkerOptions().position(latLng1).title(A));
marker2 = GoogleMap.addMarker(new MarkerOptions().position(latLng2).title(B));
marker3 = GoogleMap.addMarker(new MarkerOptions().position(latLng3).title(C));

markersToClear.add(marker2);
markersToClear.add(marker3);

for (Marker marker : markersToClear) {
    marker.remove();
}

markersToClear.clear();

// marker1 left on map

【讨论】:

    猜你喜欢
    • 2016-10-12
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 2013-06-27
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多