I just had the problem that I added multiple markers to a v3 Google Map and executed fitBounds to see them all at ones. But the zoom level was much to high, when having only one marker. Calling the setZoom() method afterwards didn’t make any difference, so I searched a little bit and found this nice snippet of code:

google.maps.event.addListener(map, 'zoom_changed', function() {
        zoomChangeBoundsListener = google.maps.event.addListener(map, 'bounds_changed', function(event) {
            if (this.getZoom() > 10) // Change max/min zoom here
                this.setZoom(10);

            google.maps.event.removeListener(zoomChangeBoundsListener);
        });
});

via Boogle’s Blog (Google Groups respectively)

  • Garland Pope

    This solved the problem of fitBounds() zooming in too far, but it created the problem of the user not being able to zoom in manually. Thoughts?

  • Garland Pope

    OK, a solution is posted in the comments of the Boogle blog entry.

    http://boogleoogle.blogspot.com/2010/04/maximum-zoom-level-when-using-fitbounds.html

  • http://alangio.com.ar Alan

    Thanks a lot!, its works great!

  • Nate Wright

    Garland, I solved this by removing zoomChangeBoundsListener from the listener on ‘zoom_changed’. I just used the following code

    var bounds_listener = google.maps.event.addListener( map, 'bounds_changed', function(event) {
    if (this.getZoom() > 15) {
    this.setZoom(15);
    }

    google.maps.event.removeListener( bounds_listener );
    });

  • Richard

    why don’t you just use the maxZoom property on the map?

    • Daniel

      Thanks Richard… haven’t checked their API for a while. This post is from 2010… maybe this property was added later… :)