Android cluster and marker clicks

百般思念 提交于 2019-11-27 13:44:04

You can create a new MarkerManager that you pass into the ClusterManager constructor. Then make a new Marker collection using MarkerManager#newCollection and add your normal Markers to the map using the MarkerManager.Collection#addMarker method.

Then, instead of calling mMap.setOnMarkerClickListener(mClusterManager), call mMap.setOnMarkerClickListener(mMarkerManager), and it will handle forwarding your Marker click events to the proper listeners. You'll also need to set up your onMarkerClick listener for normal Markers with the MarkerManager.Collection#setOnMarkerClickListener(GoogleMap.OnMarkerClickListener markerClickListener) function.

I recommend looking over the source of the MarkerManager and ClusterManager classes to get a better idea of how the classes interact.

One more way to receive the click event for Marker is using OnClusterItemClickListener interface.

Call mClusterManager.setOnClusterItemClickListener(this); and make your class implement OnClusterItemClickListener

Then inside the onClusterItemClick method, you will get the ClusterItem which is the marker that was clicked,

@Override
public boolean onClusterItemClick(ClusterItem clusterItem) {

    Toast.makeText(getActivity(), "Latitude " + clusterItem.getPosition().latitude, Toast.LENGTH_LONG).show();

    return true;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!