Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2017 16:06
Show Gist options
  • Save espritm/5b0eec6cdd4bac1704f741d7917dfb25 to your computer and use it in GitHub Desktop.
Save espritm/5b0eec6cdd4bac1704f741d7917dfb25 to your computer and use it in GitHub Desktop.
public class ClusterRenderer : DefaultClusterRenderer
private IconGenerator m_iconGeneratorForMarkerGroup;
private ImageView m_imageviewForMarkerGroup;
public ClusterRenderer(Activity context, GoogleMap map, ClusterManager clusterManager)
: base(context, map, clusterManager)
private void InitViewForMarkerGroup(Activity context)
//Retrieve views from AXML to display groups of markers (clustering)
View viewMarkerClusterGrouped = context.LayoutInflater.Inflate(Resource.Layout.marker_cluster_grouped, null);
m_imageviewForMarkerGroup = viewMarkerClusterGrouped.FindViewById<ImageView>(Resource.Id.marker_cluster_grouped_imageview);
//Configure the groups of markers icon generator with the view. The icon generator will be used to display the marker's picture with a text
m_iconGeneratorForMarkerGroup = new IconGenerator(context);
//Draw a single marker
protected override void OnBeforeClusterItemRendered(Java.Lang.Object p0, MarkerOptions markerOptions)
//Icon for single marker
//Text for Info Window
markerOptions.SetTitle(markerOptions.Position.Latitude.ToString() + ", " + markerOptions.Position.Longitude.ToString());
//Draw a grouped marker
protected override void OnBeforeClusterRendered(ICluster p0, MarkerOptions markerOptions)
//Retrieve the number we have to display inside the group marker
string sNumberOfMarkersGrouped = p0.Size.ToString();
//Icon of a group marker :
// First, set the imageview's source with the right picture
// Then, use the icon generator to set the icon of the marker with the text containing the number of markers grouped
Bitmap icon = m_iconGeneratorForMarkerGroup.MakeIcon(sNumberOfMarkersGrouped);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment