Created
November 7, 2022 16:09
-
-
Save MrJoshFisher/cd6225377122f7a2c42e1f1eeae30e54 to your computer and use it in GitHub Desktop.
[Google Map with Multiple Markers and Info Windows]
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 initMap() { | |
const map = new google.maps.Map(document.getElementById("map"), { | |
zoom: 10, | |
center: { lat: 51.3055106, lng: 0.3105068 }, | |
}); | |
setMarkers(map,locations); | |
} | |
function setMarkers(map,locations){ | |
var marker, i | |
var infowindow = new google.maps.InfoWindow(); | |
for (i = 0; i < locations.length; i++) { | |
var title = locations[i][0] | |
var lat = locations[i][1] | |
var long = locations[i][2] | |
var text = locations[i][3]; | |
var link = locations[i][4] | |
latlngset = new google.maps.LatLng(lat, long); | |
var marker = new google.maps.Marker({map: map, title: title , position: latlngset}); | |
var content = "<div class=\'infoWindow\'><h4>"+title+"</h4>" + text + "<br> <a href=\'"+link+"\'>View Location</a></div>"; | |
google.maps.event.addListener(marker,"click", (function(marker,content,infowindow){ | |
return function() { | |
infowindow.close(); | |
infowindow.setContent(content); | |
infowindow.open(map,marker); | |
}; | |
})(marker,content,infowindow)); | |
} | |
} | |
window.initMap = initMap; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment