Created
September 8, 2020 06:35
-
-
Save rashid327/f18e8f0c9e47bf4a8eeaee1ed5fe0c0b to your computer and use it in GitHub Desktop.
Setting map bounds for multiple markers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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