Skip to content Skip to sidebar Skip to footer

Google Zooming To Fit All Markers On That Page

im having difficulties figuring this out, ive looked at examples here and on the internet but still cant manage to get it to work. I have a Google v3 map which displays a number of

Solution 1:

Make use of LatLngBounds.extend() and Map.fitBounds(). Below, the fullBounds rectangle will grow to include your markers as you create them. Then, simply fit the map to that rectangle when you are done creating your markers.

var fullBounds = new google.maps.LatLngBounds();

for(var i=0;i<markers.length;i++){
  var lat=parseFloat(markers[i].getAttribute("lat"));
  var long=parseFloat(markers[i].getAttribute("long"));
  var point=new google.maps.LatLng(lat,long);

  fullBounds.extend(point);

  ...

}

map.fitBounds(fullBounds);

Post a Comment for "Google Zooming To Fit All Markers On That Page"