Google Maps v3: Enforcing min. zoom level when using fitBounds

前端 未结 8 2070
攒了一身酷
攒了一身酷 2020-12-12 15:02

I\'m drawing a series of markers on a map (using v3 of the maps api).

In v2, I had the following code:

  bounds = new GLatLngBounds();

  ... loop th         


        
8条回答
  •  半阙折子戏
    2020-12-12 15:16

    Anthony's solution is very nice. I only needed to fix the zoom for the inital page load (ensuring that you weren't too far zoomed in to start with) and this did the trick for me:

    var zoomChangeBoundsListener =
        google.maps.event.addListener(map, 'bounds_changed', function(event) {
            google.maps.event.removeListener(zoomChangeBoundsListener);
            map.setZoom( Math.min( 15, map.getZoom() ) );
        });
    
    
    map.fitBounds( zoomBounds );
    

提交回复
热议问题