Categories
JavaScript

Zoom To Fit All Markers on Google Maps

Zoom Google Maps to fit all markers on your map.

var latLngArr = [new google.maps.LatLng(52.537,-2.061), new google.maps.LatLng(52.564,-2.017)],
    bounds = new google.maps.LatLngBounds(),
    idx = 0,
    count = latLngArr.length;

for ( ; idx < count; idx++) {
  bounds.extend (latLngArr[idx]);
}

map.fitBounds(bounds);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.