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

前端 未结 8 2078
攒了一身酷
攒了一身酷 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:33

    Without trying it, I'd say you should be able to do it just by having fitBounds() before you get the zoom level, i.e.

    map.fitBounds(bounds);
    var zoom = map.getZoom();
    map.setZoom(zoom > 6 ? 6 : zoom);
    

    If you did try that and it didn't work, you can setup your map with minZoom in the MapOptions (api-reference) like this:

    var map = new google.maps.Map(document.getElementById("map"), { minZoom: 6 });
    

    This would keep the map from zooming any further out when using fitBounds().

提交回复
热议问题