1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow(), marker, i;
var allmarker = [];
var i2 = 0;
// Loop through our array of markers & place each one on the map
$.each(markers, function(key, value){
var position = new google.maps.LatLng(value.latitude, value.longitude);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: maCarte,
icon: {
url: value.icon,
size: new google.maps.Size(value.width, value.height),
anchor: new google.maps.Point(value.anchor_w, value.anchor_h)
},
title: value.title
});
allmarker[i2] = marker;
// console.log(allmarker);
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var infoWindowContent = '<div class="info_content">' + value.infoWindowContent + '</div>';
infoWindow.setContent(infoWindowContent);
infoWindow.open(maCarte, marker);
}
})(marker, i));
// Automatically center the map fitting all markers on the screen
maCarte.fitBounds(bounds);
i2++;
}); |
Partager