ClusterManager setOnCameraIdleListener

Kamy picture Kamy · Aug 11, 2016 · Viewed 7.8k times · Source

While trying to implement use ClusterManager, I noticed that the getMap().setOnCameraChangeListener(clusterManager) is deprecated. Looking at the android-maps-utils sample on Github, I noticed that getMap().setOnCameraIdleListener(mClusterManager);

When I try doing the same, I get an error because the default ClusterManager class doesn't implement GoogleMap.OnCameraIdleListener.

Yet, in my gradle file, I am using what seems to me, the latest maps-util libraries:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4.3'
}

How can I get access to the newest ClusterManager class? Thanks

Answer

yass picture yass · Aug 16, 2016

instead of:

mMap.setOnCameraChangeListener(mClusterManager);

do that:

final CameraPosition[] mPreviousCameraPosition = {null};
    googleMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
        @Override
        public void onCameraIdle() {
            CameraPosition position = googleMap.getCameraPosition();
            if(mPreviousCameraPosition[0] == null || mPreviousCameraPosition[0].zoom != position.zoom) {
                mPreviousCameraPosition[0] = googleMap.getCameraPosition();
                clusterManager.cluster();
            }
        }
    });

that will work...