markers with the exact same location and one infowindow

21 views
Skip to first unread message

Dominik Wójcik

unread,
Jul 10, 2016, 9:31:33 PM7/10/16
to Google Maps JavaScript API v3
hello

I have problem with Multiple markers with the exact same location. I create markers using "for "loop from array, where I have lat, lon, and url value.
I want to display infowindow with url value, using click action. Infowindow should show as many url addresses as there are markers.

var arr = {/literal}{$array|@json_encode}{literal}
var map;
var image_map = 'map_flag.png';
var image_map_cluster = /m';
var stylez = [
{
 featureType: "all",
 elementType: "all",
 stylers: [
{ saturation: -100 }
 ]
}
];
var marker;
var i, j;
var markers = new Array();
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: new google.maps.LatLng(51.90, 19.59),
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
zoomControl: true
});
mapType = new google.maps.StyledMapType(stylez, { 
name:"Grayscale" 
});    
map.mapTypes.set('tehgrayz', mapType);
map.setMapTypeId('tehgrayz');
for (i = 0; i < arr.length; i++) {
var latlng = new google.maps.LatLng(arr[i]['lat'], arr[i]['lon']);
marker = new google.maps.Marker({
position: latlng,
map: map,
animation: google.maps.Animation.DROP,
icon: image_map,
zIndex: i,
});
attachSecretMessage(marker, arr[i]['link'], i);
markers.push(marker);
    }

var mc = new MarkerClusterer(map, markers, {imagePath: image_map_cluster,zoomOnClick: true,maxZoom:15});

}
function attachSecretMessage(marker, secretMessage, i) {
    google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
window.location.href = secretMessage;
}
})(marker, i));
}


Reply all
Reply to author
Forward
0 new messages