相关疑难解决方法(0)

使用fitBounds()和Google Maps API V3后使用setZoom()

我正在使用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++;
Run Code Online (Sandbox Code Playgroud)

其中this.map.bounds先前定义为:

this.map.bounds = new google.maps.LatLngBounds();
Run Code Online (Sandbox Code Playgroud)

但是,我遇到的问题是this.map.map.setZoom(16);如果我使用该行不起作用this.map.map.fitBounds(this.map.bounds);,但是,我知道这行代码是正确的,因为当我注释掉fitBound()行时,setZoom()神奇地开始运行.

我有什么想法解决这个问题?我正在考虑设置一个maxZoom级别作为替代,如果我不能让它工作.

javascript google-maps google-maps-api-3 google-maps-markers

72
推荐指数
3
解决办法
9万
查看次数