Search code examples
androidgoogle-mapszooming

Zoom map after Cluster click


I am trying to implement zoom after onClusterClick but i am using this library Link and i do not how to do it. In Google library

 @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;`

but i do not have getPosition(). I have only getLatitude() and getLongitude


Solution

  • map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(getLatitude(), getLongitude()), MY_ZOOM)
    

    Or this option

    LatLngBounds.Builder builder = LatLngBounds.builder();
    for (SampleClusterItem item : cluster.getItems()) {
        builder.include(new LatLng(item.getLatitude(), item.getLongitude()));
    }
    final LatLngBounds bounds = builder.build();
    
    try {
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, PADDING));
    } catch (Exception e) {
        Log.e("TAG_SNAP", "onClusterClick: " + e.getMessage());
    }