google maps API 3 zooms out on fitBounds

前端 未结 7 1566
心在旅途
心在旅途 2021-01-11 14:48

I\'ve run into a problem where calling map.fitBounds seems to zoom out. I\'m trying to use the backbone.js router to save the map bounds in the url. I want to be able to boo

7条回答
  •  爱一瞬间的悲伤
    2021-01-11 15:29

    I was hit with the same problem and @Tomik's answer helped me resolving it. Here is the snippets of the code I used.

    To save the previous zoom and center.

    const lastMapZoom = this.map.getZoom();
    const lastMapCenter = this.map.getCenter();
    

    To set the values back.

    this.map.setCenter(lastMapZoom);
    this.map.setZoom(lastMapCenter);
    

提交回复
热议问题