Skip to content

Instantly share code, notes, and snippets.

@yuanmai
Created August 8, 2012 01:42
Show Gist options
  • Save yuanmai/3291295 to your computer and use it in GitHub Desktop.
Save yuanmai/3291295 to your computer and use it in GitHub Desktop.
Google map fitBounds
// Make an array of the LatLng's of the markers you want to show
var LatLngList = 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);
@maurusrv
Copy link

nice. thanks for this!

@esfraner
Copy link

esfraner commented Jun 9, 2021

Thanks! It was very useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment