Sometimes, we want to use setZoom() after use fitBounds() with Google Maps API V3 with JavaScript.
In this article, we’ll look at how to use setZoom() after use fitBounds() with Google Maps API V3 with JavaScript.
How to use setZoom() after use fitBounds() with Google Maps API V3 with JavaScript?
To use setZoom() after use fitBounds() with Google Maps API V3 with JavaScript, we can use the getZoom and setZoom methods.
For instance, we write
google.maps.event.addListenerOnce(map, "bounds_changed", function (event) {
if (this.getZoom() > 15) {
this.setZoom(15);
}
});
to listen to the bounds_change event on the map with addListenerOnce.
In the event listener, we call getZoom to check of the zoom level is bigger than 15.
If it is, then we call setZoom to set the zoom level to 15.
Conclusion
To use setZoom() after use fitBounds() with Google Maps API V3 with JavaScript, we can use the getZoom and setZoom methods.