Skip to content

Instantly share code, notes, and snippets.

@espritm
Created April 6, 2017 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espritm/2fe615299ac04f51f1150d7d4ad94803 to your computer and use it in GitHub Desktop.
Save espritm/2fe615299ac04f51f1150d7d4ad94803 to your computer and use it in GitHub Desktop.
public class MainActivity : AppCompatActivity, IOnMapReadyCallback, ClusterManager.IOnClusterItemInfoWindowClickListener
{
private ClusterRenderer m_ClusterRenderer;
//...
public void OnMapReady(GoogleMap map)
{
m_map = map;
//Initialize cluster manager. Setting the CameraIdleListener is mandatory
m_ClusterManager = new ClusterManager(this, m_map);
m_map.SetOnCameraIdleListener(m_ClusterManager);
//Initialize cluster renderer, and keep a reference that will be usefull for the info window's click event
m_ClusterRenderer = new ClusterRenderer(this, m_map, m_ClusterManager);
m_ClusterManager.Renderer = m_ClusterRenderer;
//Custom info window : single markers only (a click on a cluster marker should not show info window)
m_ClusterManager.MarkerCollection.SetOnInfoWindowAdapter(new CustomGoogleMapInfoWindow(this));
m_map.SetInfoWindowAdapter(m_ClusterManager.MarkerManager);
//Handle Info Window's click event
m_map.SetOnInfoWindowClickListener(m_ClusterManager);
m_ClusterManager.SetOnClusterItemInfoWindowClickListener(this);
SetupMap();
}
public void OnClusterItemInfoWindowClick(Java.Lang.Object p0)
{
//You can retrieve the ClusterItem clicked with a cast
ClusterItem itemClicked = (ClusterItem)p0;
Toast.MakeText(this, "Info Window clicked !", ToastLength.Short).Show();
//Dismiss the info window clicked
m_ClusterRenderer.GetMarker(itemClicked).HideInfoWindow();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment