Page 1 of 1

How to zoom Google map to fit all markers

Posted: Tue Jan 21, 2014 10:12 pm
by Saman

Code: Select all

//  Make an array of the LatLng's of the markers you want to show
var LatLngList = new Array (new google.maps.LatLng (52.537,-2.061), new google.maps.LatLng (52.564,-2.017));
//  Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds ();
//  Go through each...
for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
  //  And increase the bounds to take this point
  bounds.extend (LatLngList[i]);
}
//  Fit these bounds to the map
map.fitBounds (bounds); 

Re: How to zoom Google map to fit all markers

Posted: Tue Aug 12, 2014 11:58 am
by healdprice
Great!