6

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);
  • What have you tried so far? Have you tried using `OnCameraMoveListener()` which, as mentioned in the [documentation](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnCameraChangeListener), is one of the given replacement for the deprecated `OnCameraChangeListener()`? Did it not work for you? Please share code snippets and error/s shown in the logs if there are any. – Teyam Aug 24 '16 at 16:24
  • Edited to show what I've tried. – Rio Marie A. Callos Aug 25 '16 at 01:36

3 Answers3

16

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... ;-)

Ilario
  • 5,979
  • 2
  • 32
  • 46
Max Waitzman
  • 411
  • 3
  • 7
  • 2
    It doesn't support MultiListener. Is there a solution for that? – KasparTr Aug 30 '16 at 14:53
  • @KasparTr make a new class overrides clustermanager like this class MyClusterManager(context: Context?, map: GoogleMap?) : ClusterManager(context, map) { override fun onCameraIdle() { super.onCameraIdle() Log.e("CAMERA", "CAMERA IDLE") } } – Mustafa Güven Aug 09 '18 at 07:47
1

It is advisable to use newly introduced four camera listeners (OnCameraIdleListener, OnCameraMoveListener, OnCameraMoveStartedListener,OnCameraMoveCanceledListener), but if you still want to go with setOnCameraChangeListener use specific version of android-maps-utils(Given below)

compile 'com.google.maps.android:android-maps-utils:0.4.3'

in your module level gradle file. Check this answer if you want to implement new methods.

Community
  • 1
  • 1
Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49
-1

As per the documentation, this interface has been deprecated and replaced by more granular options which you could use.

This interface was deprecated. Replaced by GoogleMap.OnCameraMoveStartedListener, GoogleMap.OnCameraMoveListener and GoogleMap.OnCameraIdleListener. The order in which the deprecated onCameraChange method will be called in relation to the methods in the new camera change listeners is undefined.

Aneeb Khawar
  • 330
  • 1
  • 8