我正在使用fitBounds()函数来设置地图的缩放级别,以包括当前显示的所有标记。但是,当仅有一个标记可见时,缩放级别为100%(我认为是缩放级别20)。然而,我不希望它缩放得那么远,这样用户就可以调整标记的位置而无需缩小。
以下是我的代码:
var marker = this.map.createMarker(view.latlng, this.markerNumber);
this.map.bounds.extend(view.latlng);
this.map.map.setCenter(this.map.bounds.getCenter());
this.map.map.fitBounds(this.map.bounds);
if (this.markerNumber === 1) {
this.map.map.setZoom(16);
}
this.markerNumber++;
其中this.map.bounds先前被定义为:
this.map.bounds = new google.maps.LatLngBounds();
然而,我遇到的问题是,当我使用 this.map.map.fitBounds(this.map.bounds);
这行代码时,this.map.map.setZoom(16);
这行代码就无法工作。但是,当我注释掉 fitBound() 这一行代码时,setZoom() 就神奇地开始正常运行了。
有没有什么想法可以解决这个问题?如果无法使其正常工作,我正在考虑将最大缩放级别设置为替代方案。