On zoom event for google maps on android

前端 未结 11 2046
清酒与你
清酒与你 2020-11-30 00:04

We\'re building an application which is using the google maps api for android.

I have my MapController and MapView, and I enable the built-in zoom controls using:

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 00:36

    You can implement your own basic "polling" of the zoom value to detect when the zoom has been changed using the android Handler.

    Using the following code for your runnable event. This is where your processing should be done.

    private Handler handler = new Handler();
    
    public static final int zoomCheckingDelay = 500; // in ms
    
    private Runnable zoomChecker = new Runnable()
    {
        public void run()
        {
            checkMapIcons();
    
            handler.removeCallbacks(zoomChecker); // remove the old callback
            handler.postDelayed(zoomChecker, zoomCheckingDelay); // register a new one
        }
    };
    

    Start a callback event using

    protected void onResume()
    {
        super.onResume();
        handler.postDelayed(zoomChecker, zoomCheckingDelay);
    }
    

    and stop it when you're leaving the activity using

    protected void onPause()
    {
        super.onPause();
        handler.removeCallbacks(zoomChecker); // stop the map from updating
    }
    

    Article this is based on can be found here if you want a longer write up.

提交回复
热议问题