Rio Marie A. Callos Rio Marie A. Callos - 1 month ago 42
Android Question

Google Maps Android Clustering OnCameraChangeListener() deprecated

Using the tutorial here, I successfully implemented clustering in my Android app. Since OnCameraChangeListener() is now deprecated in com.google.android.gms:play-services:9.4.0 is there a new way to implement the part below?

private ClusterManager<MyItem> mClusterManager;
googleMap.setOnCameraChangeListener(mClusterManager);


EDIT:

I tried directly replacing setOnCameraChangeListener by setOnCameraMoveListener like

googleMap.setOnCameraMoveListener(mClusterManager);


This does not work since setOnCameraMoveListener() is expecting an object of class OnCameraMoveListener. Casting mClusterManager does not work either.

googleMap.setOnCameraMoveListener((GoogleMap.OnCameraMoveListener) mClusterManager);

Answer

You need to use

gooleMap.setOnCameraIdleListener(mClusterManager);

instead of

googleMap.setOnCameraMoveListener(mClusterManager);

You can to search for the source code of ClusterManager and you will see that ClusterManager implements the new OnCameraIdleListener.

Also you need to update to new android-maps-utils:0.4.4

(compile 'com.google.maps.android:android-maps-utils:0.4.4')

Good luck and vote up... ;-)

Comments