Google Maps v3 fitBounds() Zoom too close for single marker

前端 未结 17 2123
别那么骄傲
别那么骄傲 2020-12-12 23:28

Is there a way to set a max zoom level for fitBounds()? My problem is that when the map is only fed one location, it zooms in as far as it can go, which really

17条回答
  •  星月不相逢
    2020-12-13 00:08

    Once you've added all of the real bounds add these lines

    var offset = 0.002;     
    var center = bounds.getCenter();                            
    bounds.extend(new google.maps.LatLng(center.lat() + offset, center.lng() + offset));
    bounds.extend(new google.maps.LatLng(center.lat() - offset, center.lng() - offset));
    

    it get the center of the real bounds then adds two additional points one to the northeast and one to the southwest of you center

    This effectively sets the minimum zoom, change the value of offset to increase or decrease the zoom

提交回复
热议问题