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

前端 未结 17 2130
别那么骄傲
别那么骄傲 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 23:54

    Another solution is to expand bounds if you detect they are too small before you execute fitBounds():

    var bounds = new google.maps.LatLngBounds();
    // here you extend your bound as you like
    // ...
    if (bounds.getNorthEast().equals(bounds.getSouthWest())) {
       var extendPoint = new google.maps.LatLng(bounds.getNorthEast().lat() + 0.01, bounds.getNorthEast().lng() + 0.01);
       bounds.extend(extendPoint);
    }
    map.fitBounds(bounds);
    

提交回复
热议问题