Android Google Maps V2群集隐藏infoWindow

时间:2014-08-08 08:06:52

标签: android google-maps hide cluster-computing infowindow

在Android项目中,我使用Google Maps Android API Utility Librairy来使用群集解决方案。

在每个单个标记或聚类标记上,InfoWindow在触摸所选标记时打开。然后在触摸infoWindow时,我使用这些事件:

...
mClusterManager.setOnClusterInfoWindowClickListener(this);
mClusterManager.setOnClusterItemInfoWindowClickListener(this);
...

和:

@Override
public void onClusterInfoWindowClick(Cluster<JobItem> cluster) {
    // Here I go to a new fragment A, list of items.

}

@Override
public void onClusterItemInfoWindowClick(JobItem item) {
    // Here I go to a new fragment B, item's details

}

当我回到地图(来自片段A或B的popBackStack)时,infoWindow始终打开。当我转到片段A或B时,我想以编程方式隐藏它们。 我发现可以从markers对象调用 hideInfoWindow()方法,但在这两个事件标记中没有传递参数。

关于如何隐藏infoWindow的任何想法?

1 个答案:

答案 0 :(得分:0)

我找到了一个适合我的解决方案,在你的片段的onResume上添加这个代码,它将关闭所有打开的InfoWindow。

java.util.Collection<Marker> markerCollection = mClusterManager.getMarkerCollection().getMarkers();
for(Marker m : markerCollection){
    if(m.isInfoWindowShown())
    m.hideInfoWindow();
}