Maps API v3 Infowindows with multiple markers
http://stackoverflow.com/questions/24803074
by prateekbansal07
HTML
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<div id="map"></div>
CSS
html, body, #map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
JavaScript
var markers = [];
function initialize() {
var beaches = [
['43650 GARFIELD RD, 48038, MI',40.64473265900482, -76.13203021009522, 'Termination'],
['400 HOBART ST, 49601, MI',41.9164957,-74.0249826, 1, 'Add'], ['400 HOBART ST, 49601, MI',40.687796922427474, -76.1961573402973, 1, 'Manual'],
['550 MUNSON AVE, 49686, MI',40.686700088963974, -76.1927822281814, 1, 'Good']
];
var map1 = new google.maps.Map(document.getElementById('map'), {
zoom:13,
center: new google.maps.LatLng(40.686700088963974, -76.1927822281814),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
for (var i = 0; i < beaches.length; i++) {
var icon = "";
const svgGreenMarker = {
path: "M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
fillColor: "green",
fillOpacity: 0.1,
strokeWeight: 0,
rotation: 0,
scale: 2,
anchor: new google.maps.Point(0, 20),
};
const svgRedMarker = {
path: "M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
fillColor: "red",
fillOpacity:0.1,
strokeWeight: 0,
rotation: 0,
scale: 2,
anchor: new google.maps.Point(0, 20),
};
const svgYellowMarker = {
path: "M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75...