So, I have the following Javascript code for some custom markers:
window.addEventListener('load', initialise)
//Initialises the map view
function initialise() {
var mapOptions = {
center: new google.maps.LatLng(53.4113594, -2.1571162),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//Creates the actual Map object
var map = new google.maps.Map(document.getElementById("mapArea"), mapOptions);
setMarkers(map, myLocations);
}
var myLocations = [
['Stockport Town Hall', 'This is the town hall. Where things... happen.', 'townhall.jpg', 53.406, -2.158215, 'images/markers/townhall.png'],
['Stockport Town Centre', 'This is the centre of town. Where there are shops. And food. and... stuff', 'stockportcentre.jpg', 53.4175146, -2.1490619,
'images/markers/shopping.png'
],
['Stockport College', 'This is Stockport college. Where learning happens.', 'stockportcollege.jpg', 53.4040427, -2.1587963, 'images/markers/Learning.png'],
['Stockport Train station', 'This is the train station. Where you catch trains.', 'stockporttrainstation.jpg', 53.4056234, -2.1637525, 'images/markers/train.png']
];
function setMarkers(map, myLocations) {
for (var i in myLocations) {
var name = myLocations[i][0];
var info = myLocations[i][1];
var image = myLocations[i][2];
var lat = myLocations[i][3];
var lng = myLocations[i][4];
var indivIcon = myLocations[i][5];
var latlngset;
latlngset = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
map: map,
title: name,
position: latlngset,
icon: indivIcon
});
//content here!
var infoContent = '<h3>' + name + '</h3>' + info +
'<br /><img width = "128" height = "128" src = "images/' + image + ' " ' + '</div>';
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(
marker, 'click',
function() {
infowindow.setContent(infoContent);
infowindow.open(map, this);
});
}
}
Now, the markers work just fine. I can open them up, they auto-close and go to other markers, but the weird issue is: The infoWindows all show the "Stockport Train Station" information and I have no idea why. What is it I'm doing wrong here?