I have a javascript file like below that is init in contact us page. I added almost everything that i wanted but could't figure out how to set working info windows for each marker. In facts i understand how to set and use infoWindow but don't know where to put it in this code.
var ContactUs = function () {
return {
//main function to initiate the module
init: function () {
var neighborhoods = [
{ lat: 41.02688344, lng: 28.97104517, icon: '../Content/blue_MarkerSS.png', content: "a" },
{ lat: 41.07992535, lng: 29.02025431, icon: '../Content/blue_MarkerL.png', content: "b" },
{ lat: 41.059097, lng: 28.983857, icon: '../Content/blue_MarkerB.png', content: "c" },
{ lat: 41.08476948, lng: 28.97748649, icon: '../Content/blue_MarkerK.png', content: "d" },
{ lat: 41.05635465, lng: 28.95114452, icon: '../Content/red_MarkerS.png', content: "e" }
];
var markers = [];
var map;
map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: { lat: 41.052244, lng: 28.985637 }
});
function addMarkerWithTimeout(position, timeout, icon, content) {
window.setTimeout(function () {
markers.push(new google.maps.Marker({
position: position,
map: map,
animation: google.maps.Animation.DROP,
icon: icon
}));
}, timeout);
}
for (var i = 0; i < neighborhoods.length; i++) {
addMarkerWithTimeout(neighborhoods[i], i * 300, neighborhoods[i].icon, neighborhoods[i].content);
}
}
};
}();
UPDATE:
I have a working script like that contains infoWindows. I want to add it addMarkerWithTimeout as in first question. Think about merge two scripts that will contain infoWindows and addMarkerWithTimeout in one. My problem is just this.
Original addMarkerWithTimeout Example is HERE (i don't want that button)!
var ContactUs = function () {
return {
init: function () {
var locations = [
['a', 41.02688344, 28.97104517, 4, './Content/blue_MarkerSS.png'],
['b', 41.07992535, 29.02025431, 5, '../Content/blue_MarkerSS.png'],
['c', 41.059097, 28.983857, 3, '../Content/blue_MarkerSS.png'],
['d', 41.08476948, 28.97748649, 2, '../Content/blue_MarkerK.png'],
['e', 41.05635465, 28.95114452, 1, '../Content/red_MarkerS.png']
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: new google.maps.LatLng(41.052244, 28.985637),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: locations[i][4]
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
};
}();