0

我有一个问题,我认为 fitBounds 调用没有正确设置缩放级别。我已经设法在这里重现了我的测试用例http://tom.haddons.net/map.html - 基本上四个外点是我设置的边界,如果你加载页面,然后放大一级,它们'都仍然可见。那么为什么谷歌地图不设置缩放级别呢?

谢谢,汤姆

4

1 回答 1

0

我通过执行以下操作设法解决了这个问题:

  var minlatminlong = new google.maps.LatLng({{ min_latitude }}, {{ min_longitude }});
  var minlatmaxlong = new google.maps.LatLng({{ min_latitude }}, {{ max_longitude }});
  var maxlatminlong = new google.maps.LatLng({{ max_latitude }}, {{ min_longitude }});
  var maxlatmaxlong = new google.maps.LatLng({{ max_latitude }}, {{ max_longitude }});

  zoomChangeBoundsListener = google.maps.event.addListener(map, 'bounds_changed', function(){
      var bounds = this.getBounds();
      if ((bounds.getSouthWest().lng() > {{ min_longitude }}) || (bounds.getNorthEast().lng() < {{ max_longitude }}) || (bounds.getSouthWest().lat() > {{ min_latitude }}) || (bounds.getNorthEast().lat() < {{ max_latitude }})) {
          this.setZoom(this.getZoom() - 1);
      } else {
          google.maps.event.removeListener(zoomChangeBoundsListener);
      }
  });

请注意,包含在“{{”和“}}”中的任何内容都是我传递给 html 模板的变量。

于 2013-04-09T10:53:03.237 回答