Created
July 5, 2013 09:53
-
-
Save ericchen/5933441 to your computer and use it in GitHub Desktop.
Auto Zoom To Fit All Markers on Google Maps API v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Actually still relevant and I needed exactly this 👍