map
map copied to clipboard
Auto-Center based on Marker Positions
How can I auto center or set zoom so that it covers all markers based on the positions of my markers.
You can make use of the fitBounds()
method: https://developers.google.com/maps/documentation/javascript/reference/map#Map.fitBounds
You could iterate through your markers and call their getPosition()
method and extend a LatLngBounds object: https://developers.google.com/maps/documentation/javascript/reference/coordinates#LatLngBounds