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

前端 未结 6 1075
一向
一向 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:11

    I have simple and dirty solution.
    Use If else ...

    var marker = this.map.createMarker(view.latlng, this.markerNumber);
    this.map.bounds.extend(view.latlng);
    this.map.map.setCenter(this.map.bounds.getCenter()); 
    if (this.markerNumber === 1) {
      this.map.map.setZoom(16);
    } else {
       this.map.map.fitBounds(this.map.bounds);
    }       
    this.markerNumber++;
    

提交回复
热议问题