Using setZoom() after using fitBounds() with Google Maps API V3

前端 未结 6 1079
一向
一向 2020-12-04 09:28

I\'m using fitBounds() to set the zoom level on my map too include all the markers currently displayed. However, when I have only one marker visible, the zoom level is 100%

6条回答
  •  囚心锁ツ
    2020-12-04 10:21

    All the solutions with event listeners didn't work for me (this.getZoom() always is undefined in the callback and this.setZoom() has no effect).

    I came up with this solution which worked nicely:

    function set_zoom() {
        if(map.getZoom()) {map.setZoom(map.getZoom() - 1);}
        else {setTimeout(set_zoom, 5);}
    }
    setTimeout(set_zoom, 5);
    

提交回复
热议问题