Article Image Google Maps v3: Zoom map to fit a set of markers Blog Logo Tom Raithel on 15 Jan 2013 read Following function returns a google.maps.LatLngBounds object for an array of google.maps.Marker /** * Returns a bounds object for a given list of markers * @param {array} markers The markers * @return {LatLngBounds} The bounds object */ getBoundsForMarkers = function(markers) { var bounds, marker, _i, _len; bounds = new google.maps.LatLngBounds(); for (_i = 0, _len = markers.length; _i < _len; _i++) { marker = markers[_i]; bounds.extend(marker.getPosition()); } return bounds; }; Assuming we have an array with markers called myMarkers and a local map object, we can use the function to calculate the bounds and apply it to the map: var bounds; bounds = getBoundsForMarkers(myMarkers); // Apply the bounds to map map.fitBounds(bounds); Written by Blog Logo Tom Raithel Published 15 Jan 2013 Supported by Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus