Domanda

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

Nessuna soluzione corretta

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top