Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

zoom level listener in google maps v2 in android

I'm developing an Android app that is supposed to use Google Maps v2. Now i'm stuck at finding when zoom level of map has changed. Can anyone help me?Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you're looking for how to determine if the zoom level has changed from the previous zoom level, here's what I'd suggest:

Define an instance variable to keep track of the previous zoom level:

//Initialize to a non-valid zoom value
private float previousZoomLevel = -1.0f;

Also, define an instance variable to let you know if the map is zooming:

private boolean isZooming = false;

When you setup your GoogleMap instance, give it an OnCameraChangeListener...

//mMap is an instance of GoogleMap
mMap.setOnCameraChangeListener(getCameraChangeListener());

Now, define the OnCameraChangeListener that will determine if the zoom level has changed:

public OnCameraChangeListener getCameraChangeListener()
{
    return new OnCameraChangeListener() 
    {
        @Override
        public void onCameraChange(CameraPosition position) 
        {
            Log.d("Zoom", "Zoom: " + position.zoom);

            if(previousZoomLevel != position.zoom)
            {
                isZooming = true;
            }

            previousZoomLevel = position.zoom;
        }
    };
}

Now, you can check the value of isZooming to know if you are changing zoom levels.

Make sure to set

isZooming = false;

after you've completed whatever action relies on knowing if the map is zooming.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...