GoogleMap onCameraIdle event not firing

In some limited testing, it appears the v2 version of the Google Maps API only supports one idle event listener (i.e. the last registered listener) - so is it possible some other code also registered a listener?

So, for example:

mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
    @Override
    public void onCameraIdle() {
        Log.e(TAG,"Listener 1");
    }
});
mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
    @Override
    public void onCameraIdle() {
        Log.e(TAG,"Listener 2");
    }
});

In the above example, only "Listener 2" is ever seen. (This is also true for the setOnCameraMoveListener and so I'd assume all the map camera events behave this way.

Assuming you overcome this limitation, one suggestion is to add the clusterManager instance as an idle camera listener - the ClusterManager implements the GoogleMap.OnCameraIdleListener interface (i.e. onCameraIdle method) and has its own logic for properly deciding on when to re-cluster. For example, it avoids reclustering on a pan operation (i.e. zoom not changed). It also propogates the event to the renderer implementation.

So in the OP code it would be

map.setOnCameraIdleListener(clusterManager);

If you must see the event, then be the only registered listener and then propagate the event to the cluster manager by directly invoking its onCameraIdle.

Also, the '+' in gradle dependencies indicates any version ">=" the version specified satifies the dependency.


The 'onCameraIdle' event was not firing because I called 'setOnCameraIdleListener' on another class.

Source code from my question

FragMap:

@Override
public void onMapReady(GoogleMap googleMap) {
    if (DataPackage.getEQMarkerManager() == null) {
        if (!DataPackage.initializeEQMarkerManager(getActivity(), googleMap)) {
            Log.w(Tag, "EQMarkerManager initialization failure");
        }
    }
}

EQMarkerManager:

public EQMarkerManager(Context ctx, GoogleMap map) {
    // ...
    clusterManager = new ClusterManager<>(ctx, map);
    clusterManager.setRenderer(new EQRenderer<>(ctx, map, clusterManager));

    map.setOnCameraIdleListener(this);

    clusterManager.addItems(markers);
}


initializeEQMarkerManager method does initialize EQMarkerManager class and EQMarkerManager#ctor calls setOnCameraIdleListener. I don't know much about android, so I'm completely sure about those code works. But it wasn't :/

Anyway, I solve this problem by calling setOnCameraIdleListener inside of FragMap.

@Override
public void onMapReady(GoogleMap googleMap) {
    if (DataPackage.getEQMarkerManager() == null) {
        if (!DataPackage.initializeEQMarkerManager(getActivity())) {
            Log.w(Tag, "EQMarkerManager initialization failure");
            return;
        }
    }

    googleMap.setOnCameraIdleListener(DataPackage.getEQMarkerManager());
}