On zoom event for google maps on android

Solution 1:

With the Google Maps Android API v2 you can use a GoogleMap.OnCameraChangeListener like this:

mMap.setOnCameraChangeListener(new OnCameraChangeListener() {

    private float currentZoom = -1;

    @Override
    public void onCameraChange(CameraPosition pos) {
        if (pos.zoom != currentZoom){
            currentZoom = pos.zoom;
            // do you action here
        }
    }
});

Solution 2:

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.

Solution 3:

I use this library which has an onZoom function listener. http://code.google.com/p/mapview-overlay-manager/. Works well.

Solution 4:

As the OP said, use the onUserInteractionEvent and do the test yourself.