ClusterManager setOnCameraIdleListener

我的梦境 提交于 2020-01-13 00:50:14

问题


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


回答1:


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




回答2:


after play-services-maps 9.4.0 version of the API they change GoogleMap.OnCameraChangeListener to this 3 listeners

GoogleMap.OnCameraMoveStartedListener,

GoogleMap.OnCameraMoveListener,

GoogleMap.OnCameraIdleListener.



来源:https://stackoverflow.com/questions/38906000/clustermanager-setoncameraidlelistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!