当用户停止移动相机时,Android google maps v2会执行asynctask

Luk*_*nda 2 android google-maps android-asynctask

我正在制作一个使用谷歌地图api v2的应用程序.我的问题是,当我注册摄像机更改监听器时,每当摄像机移动时,它就会在移动停止时执行.我想实现后者.如何修改我的代码才能在移动停止时注册?

这是我的代码:

mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition position) {
                LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
                ne = bounds.northeast;
                sw = bounds.southwest;
                ne1 = ne.latitude;
                ne2 = ne.longitude;
                sw1 = sw.latitude;
                sw2 = sw.longitude;
                new DownloadJSON().execute();
            }
        });
Run Code Online (Sandbox Code Playgroud)

Luk*_*nda 7

我实现了自定义计时器,只有在满足条件时才会在一定时间后执行.这是我的代码:

mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
                @Override
                public void onCameraChange(CameraPosition position) {
                    LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
                    ne = bounds.northeast;
                    sw = bounds.southwest;
                    if(t!=null){
                        t.purge();
                        t.cancel();
                    }
                    t = new Timer();
                    t.schedule(new TimerTask() {
                        public void run() {
                            if(ne1 != ne.latitude && ne2 != ne.longitude && sw1 != sw.latitude && sw2 != sw.longitude){
                                ne1 = ne.latitude;
                                ne2 = ne.longitude;
                                sw1 = sw.latitude;
                                sw2 = sw.longitude;
                                Log.d("Tag","Refreshing data");
                                new DownloadJSON().execute();
                                t.cancel();
                            }
                            else{
                            ne1 = ne.latitude;
                            ne2 = ne.longitude;
                            sw1 = sw.latitude;
                            sw2 = sw.longitude;}
                            t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
                        }
                    }, 1000);
                    //new DownloadJSON().execute();
                }
            });
Run Code Online (Sandbox Code Playgroud)