Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current GoogleMap zoom level?

On GoogleMap android API v2, how do I get the current map zoom level? On API v1, there used to be float MapView.getZoomLevel(), but there appears to be nothing similar on the API version I am using, and that Google recommends.

I've thought of using a class variable to save the zoom level manually via a zoom button click listener, but this doesn't solve the problem for pinch-type zooming.

Why do I need the current zoom level? I am restricting the map range to a certain rectangle and want any moves that would otherwise leave this rectangle, bounce back. This animation requires me to use a zoom level, for without it, the default maximum zoom level is used. What I really want is to maintain the zoom level used before the move attempt.

protected void recenterMap() {
    map.getMinZoomLevel();
    if(MAP_BOUNDS.contains(map.getCameraPosition().target) == false) {
        CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(MAP_CENTER)      
        .zoom(current_zoom)
        .build();     

        map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    } else {
        MAP_CENTER = map.getCameraPosition().target;
    }
}

Notice that the variable current_zoom is what I need to define.

like image 693
jhc Avatar asked Feb 14 '13 21:02

jhc


People also ask

Which method is used to get the current zoom level of the map?

Maps API getZoom() Method The getZoom() method returns the current zoom level of the map.

How do I see the zoom level on Google Maps?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.

How do you get the current zoom level in leaflet?

A leaflet map has several ways to control the zoom level shown, but the most obvious one is setZoom() . For example, map. setZoom(0); will set the zoom level of map to 0 .

How do you get the current zoom level on Google Maps flutter?

You can get the current zoom this way: float zoom=googleMap. getCameraPosition().


1 Answers

For Android, try getting the current CameraPosition, and getting the zoom from that.
I believe it's:

map.getCameraPosition().zoom
like image 118
Chris B. Avatar answered Oct 23 '22 04:10

Chris B.