Google Maps API fitBounds doesn't set zoom correctly

I'm have an issue where I don't think the fitBounds call is setting the zoom level appropriately. I have managed to reproduce my test case here http://tom.haddons.net/map.html - basically the four outer points are the bounds I'm setting, and if you load the page, and then zoom in one level they're all still visible. So why isn't google maps setting the zoom level to that?

Thanks, Tom


I managed to work around this by doing the following:

  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);
      }
  });

Note that anything enclosed in '{{' and '}}' is a variable I'm passing into the html template.

链接地址: http://www.djcxy.com/p/81538.html

上一篇: Google地图API V3 fitBounds()不起作用

下一篇: Google Maps API fitBounds不会正确设置缩放