Я зацикливаюсь на массиве для создания маркеров и информационных окон, но информационное окно всегда прикрепляется к первому маркеру ... (даже если вы щелкнете по другому маркеру)
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(50.902946,4.241436),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
setMarkers(map, shops);
}
var shops = [['United Brands', 51.218342, 4.405464, 4, 'ZZEERRR'],['United Brands', 51.162582, 4.991303, 4, 'ZZEERRR'],['United Brands Hasselt', 50.929314, 5.339501, 4, 'ZZEERRR'],['United Brands Oud-Turnhout', 51.320259, 4.974206, 4, 'ZZEERRR'],['United Brands Leuven', 50.879509, 4.705221, 4, 'ZZEERRR'],['United Brands Veurne', 51.083534, 2.644152, 4, 'ZZEERRR'],['United Brands Wijnegem', 51.222084, 4.498419, 4, 'ZZEERRR'],['United Brands Knokke', 51.340641, 3.234586, 4, 'ZZEERRR'],['United Brands Aalst', 50.938343, 4.034963, 4, 'ZZEERRR'],['UBextreme', 51.052570, 3.723077, 4, 'ZZEERRR'],['UBextreme', 51.218273, 4.402394, 4, 'ZZEERRR']];
function setMarkers(map, locations) {
for (var i = 0; i < locations.length; i++) {
var shop = locations[i];
var myLatLng = new google.maps.LatLng(shop[1], shop[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
animation: google.maps.Animation.DROP,
title: shop[0],
zIndex: shop[3],
clickable: true
});
var infowindow = new google.maps.InfoWindow({ content: shop[4] });
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
}
initialize();