【问题标题】:Google Maps API fitBounds doesn't set zoom correctlyGoogle Maps API fitBounds 未正确设置缩放
【发布时间】:2013-03-28 22:58:56
【问题描述】:

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

谢谢,汤姆

【问题讨论】:

标签: google-maps-api-3 fitbounds


【解决方案1】:

我通过以下方式设法解决了这个问题:

  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 模板的变量。

【讨论】:

    猜你喜欢
    • 2011-01-27
    • 2015-08-27
    • 2011-03-16
    • 2019-12-26
    • 2023-03-08
    • 2012-11-16
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多