Google Maps V2 - Android - Get the current zoom level

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

MapView mGoogleMapView;


int zoomLevel = mGoogleMapView.getZoomLevel();

I am aware of the methods getMinZoomLevel() and getMaxZoomLevel() however I can't find anything in the Android GMap V2 documentation that will give the current zoom level. Does anyone have any pointers on how to do this?

Any help would be appreciated.

42235 次浏览
GoogleMap map;

....

float zoom = map.getCameraPosition().zoom;

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 service 9.4.0 OnCameraChangeListener has been deprecated and it will no longer work soon.Alternately they are replaced by OnCameraMoveStarted‌​Listener,OnCameraMoveListener,OnCameraMoveCancel‌​edListener and OnCameraIdleListener.

Hence we can use OnCameraIdleListener here to get camera's current zoom level.

Code Sample:

map.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
@Override
public void onCameraIdle() {
int zoomLevel = map.getCameraPosition().zoom;
//use zoomLevel value..
}
});