Google Maps V2 - Android - Get current zoom level

How to get the current zoom level as an integer in GoogleMap. I need to take this code from GMaps v1.1:

MapView mGoogleMapView; int zoomLevel = mGoogleMapView.getZoomLevel(); 

I know the getMinZoomLevel () and getMaxZoomLevel () methods, however I cannot find anything in the Android GMap V2 documentation that will give the current zoom level. Does anyone have pointers on how to do this?

Any help would be appreciated.

+42
java android google-maps-android-api-2 android-maps-v2
May 03 '13 at 19:48
source share
3 answers
 GoogleMap map; 

....

 float zoom = map.getCameraPosition().zoom; 
+141
May 03 '13 at 19:51
source share

I think OnCameraChangeListener will do the trick.

 map.setOnCameraChangeListener(new OnCameraChangeListener() { private float currentZoom = -1; @Override public void onCameraChange(CameraPosition position) { if (position.zoom != currentZoom){ currentZoom = position.zoom; // here you get zoom level } } }); 

Update:

From Google Play 9.4.0, OnCameraChangeListener is deprecated and it will no longer work anytime soon. Subsequently, they are replaced by OnCameraMoveStarted Listener , OnCameraMoveListener , OnCameraMoveCancel edListener and OnCameraIdleListener .

Therefore, we can use OnCameraIdleListener to get the current zoom level of the camera.

Code example:

 map.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() { @Override public void onCameraIdle() { int zoomLevel = map.getCameraPosition().zoom; //use zoomLevel value.. } }); 
+32
May 03 '13 at 20:14
source share

Call getCameraPosition() on GoogleMap and read the zoom field from the resulting CameraPosition object .

+6
May 03 '13 at 19:51
source share



All Articles