Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to uncluster on single tap on a cluster marker maps v2

I am using Google Maps Marker Clustering Utility to cluster the markers. It unclusters on double tapping. Is it possible to do it manually on single click.

like image 596
geekinthepink Avatar asked Aug 20 '14 01:08

geekinthepink


People also ask

How do I change the marker on Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do I use marker clusters in Google Maps?

To navigate, press the arrow keys. The number on a cluster indicates how many markers it contains. Notice that as you zoom into any of the cluster locations, the number on the cluster decreases, and you begin to see the individual markers on the map. Zooming out of the map consolidates the markers into clusters again.


2 Answers

Bit late to the party

In your onClusterClick function:

LatLngBounds.Builder builder = LatLngBounds.builder();
for (ClusterItem item : cluster.getItems()) {
    builder.include(item.getPosition());
}
final LatLngBounds bounds = builder.build();
getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
like image 106
Kibi Avatar answered Oct 05 '22 23:10

Kibi


    mClusterManager
            .setOnClusterClickListener(new OnClusterClickListener<MyItem>() {
                @Override
                public boolean onClusterClick(final Cluster<MyItem> cluster) {
                    map.animateCamera(CameraUpdateFactory.newLatLngZoom(
                            cluster.getPosition(), (float) Math.floor(map
                                    .getCameraPosition().zoom + 1)), 300,
                            null);
                    return true;
                }
            });

you can do that on the click of the marker too , but before that you need to do map.setOnMarkerClickListener(mClusterManager);

so that cluster manager gets the click events and you can do

mClusterManagersetOnClusterItemClickListener(new OnClusterItemClickListener<MyItem>() {

}
like image 20
CommandSpace Avatar answered Oct 05 '22 23:10

CommandSpace