Skip to content

Instantly share code, notes, and snippets.

@ericchen
Created July 5, 2013 09:53
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ericchen/5933441 to your computer and use it in GitHub Desktop.
Save ericchen/5933441 to your computer and use it in GitHub Desktop.
Auto Zoom To Fit All Markers on Google Maps API v3
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);
@cbdelavenne
Copy link

Thanks! Actually still relevant and I needed exactly this 👍

@tiadotdev
Copy link

Thanks!

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