How to zoom Google map to fit all markers

Web programming topics
Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to zoom Google map to fit all markers

Post by Saman » Tue Jan 21, 2014 10:12 pm

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); 
healdprice
Corporal
Corporal
Posts: 3
Joined: Tue Aug 12, 2014 2:26 am

Re: How to zoom Google map to fit all markers

Post by healdprice » Tue Aug 12, 2014 11:58 am

Great!
Post Reply

Return to “Web programming”