Android google maps v2 execute asynctask when user stops moving the camera

Lukas Anda

I am making an app which is using google maps api v2. My problem is that when I register camera change listener, it executes each time the camera moves not when the moving stops. I want to achieve the latter. How can I modify my code to register only when moving stops ?

Here is my code:

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();
            }
        });
Lukas Anda

I implemented custom timer to execute after certain time only when conditions are met. Here is my code:

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();
                }
            });

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to animate the camera to a specified location in Google Maps v2 for Android?

分類Dev

Google Maps Android API v2

分類Dev

Circle on Google Maps for Android v2 is flickering when size changes by seekbar

分類Dev

Google Maps Android API v2 Authorization failure

分類Dev

Can't connect to Google Maps Api Android V2

分類Dev

Overlay an image on google maps android api v2

分類Dev

Google Maps Activity V2 Android Studio

分類Dev

Android 2.3およびgoogle maps API v2

分類Dev

Android Google Maps API v2:方位位置を取得する

分類Dev

Adding Multiple Markers in real time google maps v2 android

分類Dev

How to manage Markers well using google maps api v2 on android

分類Dev

Google android maps api v2マーカータイトルを常に表示

分類Dev

Animated Transparent Circle on Google Maps v2 is NOT animating correctly

分類Dev

How to set api key for Google maps v2

分類Dev

Google maps v2 not displayed on new activity

分類Dev

Google Maps V2 - API key not found Error Message

分類Dev

android maps api v2 adding multiple circles

分類Dev

access maps v2 with calabash-android

分類Dev

access maps v2 with calabash-android

分類Dev

Google Maps Android API v2のMapFragmentにカスタムコントロールを追加する方法

分類Dev

Google Maps V2 Androidでマーカーのアイコンのサイズを指定する方法

分類Dev

Google Maps V2 Androidでマーカーのアイコンのサイズを指定する方法

分類Dev

Google Maps V2 Androidでマーカーのアイコンのサイズを指定する方法

分類Dev

Android Google Maps v2:マーカーサイズをアニメーション化

分類Dev

Google Maps Android API V2で白地図しか入手できないのはなぜですか?

分類Dev

Android Google Maps v2は、JSON配列phpmySQLからマップマーカーを追加します

分類Dev

Android detect if user stopped moving

分類Dev

Android AsyncTask execute every x minutes

分類Dev

Android app stops working after moving to using creating the layout with java

Related 関連記事

  1. 1

    How to animate the camera to a specified location in Google Maps v2 for Android?

  2. 2

    Google Maps Android API v2

  3. 3

    Circle on Google Maps for Android v2 is flickering when size changes by seekbar

  4. 4

    Google Maps Android API v2 Authorization failure

  5. 5

    Can't connect to Google Maps Api Android V2

  6. 6

    Overlay an image on google maps android api v2

  7. 7

    Google Maps Activity V2 Android Studio

  8. 8

    Android 2.3およびgoogle maps API v2

  9. 9

    Android Google Maps API v2:方位位置を取得する

  10. 10

    Adding Multiple Markers in real time google maps v2 android

  11. 11

    How to manage Markers well using google maps api v2 on android

  12. 12

    Google android maps api v2マーカータイトルを常に表示

  13. 13

    Animated Transparent Circle on Google Maps v2 is NOT animating correctly

  14. 14

    How to set api key for Google maps v2

  15. 15

    Google maps v2 not displayed on new activity

  16. 16

    Google Maps V2 - API key not found Error Message

  17. 17

    android maps api v2 adding multiple circles

  18. 18

    access maps v2 with calabash-android

  19. 19

    access maps v2 with calabash-android

  20. 20

    Google Maps Android API v2のMapFragmentにカスタムコントロールを追加する方法

  21. 21

    Google Maps V2 Androidでマーカーのアイコンのサイズを指定する方法

  22. 22

    Google Maps V2 Androidでマーカーのアイコンのサイズを指定する方法

  23. 23

    Google Maps V2 Androidでマーカーのアイコンのサイズを指定する方法

  24. 24

    Android Google Maps v2:マーカーサイズをアニメーション化

  25. 25

    Google Maps Android API V2で白地図しか入手できないのはなぜですか?

  26. 26

    Android Google Maps v2は、JSON配列phpmySQLからマップマーカーを追加します

  27. 27

    Android detect if user stopped moving

  28. 28

    Android AsyncTask execute every x minutes

  29. 29

    Android app stops working after moving to using creating the layout with java

ホットタグ

アーカイブ