我有一些普通标记和聚类标记。 googleMap.setOnMarkerClickListener(mClusterManager)侦听器会覆盖普通标记侦听器,并且普通标记单击不起作用。因此,我要分别处理两个标记单击。
答案 0 :(得分:1)
ClusterManager
为此具有单独的方法:
setOnClusterItemClickListener
单击Marker
的句柄
setOnClusterClickListener
单击Cluster
的句柄
Marker
和Cluster
都是地图上的标记。您指定ClusterManager
将管理通过googleMap.setOnMarkerClickListener(mClusterManager)
进行的标记点击。
现在您需要为setOnClusterItemClickListener
设置setOnClusterClickListener
和ClusterManager
样品
googleMap.setOnMarkerClickListener(mClusterManager)
mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<ClusterItemClass>(){
@Override
public boolean onClusterClick(Cluster<ClusterItemClass> cluster) {
//logic for handle on cluster click
}
});
mClusterManager.OnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<ClusterItemClass>(){
@Override
public boolean onClusterItemClick(ClusterItemClass item) {
//logic for handle on cluster item click
}
});
在Documentation中查看更多信息
答案 1 :(得分:-2)
我从How to manage click on marker which is not in Cluster in Android Google Map API?那里得到了解决方法
对于普通标记
googleMap.setOnMarkerClickListener(mClusterManager.getMarkerManager());
MarkerManager.Collection normalMarkersCollection = mClusterManager.getMarkerManager().newCollection();
创建普通标记
MarkerOptions markerOptions = MarkerOptions()
.position(new LatLng(...))
.title("Title")
.snippet("Description")
将普通标记添加到“ normalMarkersCollection”中
normalMarkersCollection.addMarker(markerOptions)
为普通标记设置点击。
normalMarkersCollection.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener {
public boolean onMarkerClick(marker: Marker) {
// NORMAL MARKER CLICKED!
return false;
}
});
用于群集标记
mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<ClusterItemClass>(){
@Override
public boolean onClusterClick(Cluster<ClusterItemClass> cluster) {
//logic for handle on cluster click
}
});
mClusterManager.OnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<ClusterItemClass>(){
@Override
public boolean onClusterItemClick(ClusterItemClass item) {
//logic for handle on cluster item click
}
});