Search in sources :

Example 1 with ClusterItem

use of com.google.maps.android.clustering.ClusterItem in project android-maps-utils by googlemaps.

the class CustomMarkerClusteringDemoActivity method onClusterClick.

@Override
public boolean onClusterClick(Cluster<Person> cluster) {
    // Show a toast with some info when the cluster is clicked.
    String firstName = cluster.getItems().iterator().next().name;
    Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();
    // Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
    // inside of bounds, then animate to center of the bounds.
    // Create the builder to collect all essential cluster items for the bounds.
    LatLngBounds.Builder builder = LatLngBounds.builder();
    for (ClusterItem item : cluster.getItems()) {
        builder.include(item.getPosition());
    }
    // Get the LatLngBounds
    final LatLngBounds bounds = builder.build();
    // Animate camera to the bounds
    try {
        getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : ClusterItem(com.google.maps.android.clustering.ClusterItem) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds)

Aggregations

LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 ClusterItem (com.google.maps.android.clustering.ClusterItem)1