Skip to content

Instantly share code, notes, and snippets.

@espritm
Created April 5, 2017 13:39
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/9d6321c4a1c47f24c65f7663fd1789e9 to your computer and use it in GitHub Desktop.
Save espritm/9d6321c4a1c47f24c65f7663fd1789e9 to your computer and use it in GitHub Desktop.
public class MainActivity : AppCompatActivity, IOnMapReadyCallback
{
private ClusterManager m_ClusterManager;
//...
public void OnMapReady(GoogleMap map)
{
m_map = map;
//Initialise cluster manager. Setting the CameraIdleListener is mandatory
m_ClusterManager = new ClusterManager(this, m_map);
m_map.SetOnCameraIdleListener(m_ClusterManager);
SetupMap();
}
private void SetupMap()
{
//Show Grenoble on the map
LatLng LatLonGrenoble = new LatLng(45.188529, 5.724523);
m_map.MoveCamera(CameraUpdateFactory.NewLatLngZoom(LatLonGrenoble, Resources.GetInteger(Resource.Integer.default_zoom_level_googlemaps)));
List<ClusterItem> lsMarkers = new List<ClusterItem>();
//Add 50 markers using a spiral algorithm (cheers SushiHangover)
for (int i = 0; i < 50; ++i)
{
double theta = i * Math.PI * 0.33f;
double radius = 0.005 * Math.Exp(0.1 * theta);
double x = radius * Math.Cos(theta);
double y = radius * Math.Sin(theta);
ClusterItem newMarker = new ClusterItem(LatLonGrenoble.Latitude + x, LatLonGrenoble.Longitude + y);
lsMarkers.Add(newMarker);
}
//Add markers to the map through the cluster manager
m_ClusterManager.AddItems(lsMarkers);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment