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

前端 未结 17 2094
别那么骄傲
别那么骄傲 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-12 23:59

    The way I prevent the map from zooming in to far is by adding this line of code:

    var zoomOverride = map.getZoom();
            if(zoomOverride > 15) {
            zoomOverride = 15;
            }
          map.setZoom(zoomOverride);
    

    Directly after this line:

    map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
    

    Feel free to change the zoom level to whatever level you don’t want the map to zoom past.

    If you have any problems or questions, just leave me a comment on the blog post I wrote about this at http://icode4you.net/creating-your-own-store-locator-map-how-to-prevent-the-map-from-zooming-in-too-close-on-a-single-marker

提交回复
热议问题