不建议使用OnCameraChangeListener() [英] OnCameraChangeListener() is deprecated

查看:779
本文介绍了不建议使用OnCameraChangeListener()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,回顾我的旧代码,我发现 OnCameraChangeListener()现在已被弃用.

Today, looking back at my old code, I've found out that OnCameraChangeListener() is now deprecated.

我发现很难理解如何修复我的这段代码:

I'm finding difficult to understand how to fix this piece of code of mine:

mGoogleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        // Cleaning all the markers.
        if (mGoogleMap != null) {
            mGoogleMap.clear();
        }

        mPosition = cameraPosition.target;
        mZoom = cameraPosition.zoom;

        if (mTimerIsRunning) {
            mDragTimer.cancel();
        }

        mDragTimer.start();
        mTimerIsRunning = true;
    }
});

新的侦听器(aka OnCameraMoveListener())方法 onCameraMove()没有 CameraPosition cameraPosition 输入变量,所以我我很迷路:有没有办法回收我的旧代码?

The new listener (aka OnCameraMoveListener()) method onCameraMove() doesn't have a CameraPosition cameraPosition input variable, so I'm pretty lost: is there a way to recycle my old code?

此处是一些参考

推荐答案

play-services-maps 9.4.0版的API ,它们用三个摄像头监听器替换了GoogleMap.OnCameraChangeListener():

In play-services-maps 9.4.0 version of the API, They replaced GoogleMap.OnCameraChangeListener() with three camera listeners :

  • GoogleMap.OnCameraMoveStartedListener
  • GoogleMap.OnCameraMoveListener
  • GoogleMap.OnCameraIdleListener
  • GoogleMap.OnCameraMoveStartedListener
  • GoogleMap.OnCameraMoveListener
  • GoogleMap.OnCameraIdleListener

根据您的代码,我认为您需要像这样使用GoogleMap.OnCameraIdleListenerGoogleMap.OnCameraMoveStartedListener:

Based on your code, I think you need to use GoogleMap.OnCameraIdleListener and GoogleMap.OnCameraMoveStartedListener like this:

mGoogleMap.setOnCameraMoveStartedListener(new GoogleMap.OnCameraMoveStartedListener() {
            @Override
            public void onCameraMoveStarted(int i) {
                mDragTimer.start();
                mTimerIsRunning = true;
            }
        });

        mGoogleMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
            @Override
            public void onCameraIdle() {
                // Cleaning all the markers.
                if (mGoogleMap != null) {
                    mGoogleMap.clear();
                }

                mPosition = mGoogleMap.getCameraPosition().target;
                mZoom = mGoogleMap.getCameraPosition().zoom;

                if (mTimerIsRunning) {
                    mDragTimer.cancel();
                }

            }
        });

这篇关于不建议使用OnCameraChangeListener()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆