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.
Maps API getZoom() Method The getZoom() method returns the current zoom level of the map.
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.
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 .
You can get the current zoom this way: float zoom=googleMap. getCameraPosition().
For Android, try getting the current CameraPosition, and getting the zoom from that.
I believe it's:
map.getCameraPosition().zoom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With