Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Last active October 7, 2015 03:28
Show Gist options
  • Select an option

  • Save wholypantalones/3098400 to your computer and use it in GitHub Desktop.

Select an option

Save wholypantalones/3098400 to your computer and use it in GitHub Desktop.
Google Maps Zoom To Fit All Markers
// create an array of coordinates to zoom on
var latlng = [{
name: "South West Marker",
latlng: new google.maps.LatLng(swLat, swLng)
}, {
name: "North East Marker",
latlng: new google.maps.LatLng(neLat, neLng)
}];
var latlngbounds = new google.maps.LatLngBounds();
for (var i = 0; i < latlng.length; i++) {
latlngbounds.extend(latlng[i].latlng);
}
// zoom on coordinates
map.fitBounds(latlngbounds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment