Skip to content

Instantly share code, notes, and snippets.

@rashid327
Created September 8, 2020 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashid327/f18e8f0c9e47bf4a8eeaee1ed5fe0c0b to your computer and use it in GitHub Desktop.
Save rashid327/f18e8f0c9e47bf4a8eeaee1ed5fe0c0b to your computer and use it in GitHub Desktop.
Setting map bounds for multiple markers
function setMarkers(map) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < restaurants.length; i++) {
var restaurant = restaurants[i];
var layerposit = (restaurant[4] == 1 ? 999 : restaurant[3]);
var marker = new google.maps.Marker({
position: {
lat: restaurant[1],
lng: restaurant[2]
},
map: map,
title: restaurant[0],
zIndex: layerposit
});
bounds.extend(marker.getPosition());
}
map.fitBounds(bounds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment