GMaps: how to open all infoWindow when loaded map


Simple you can do it with some simple line code:

//...after addMarker
for(var i in map.markers){
    (map.markers[i].infoWindow).open(map.map,map.markers[i]);
}

Example:
javascript infoWindow open

...
            for (var i in j){
                $('#employeemaps tbody').append(line(j[i]))
                
                var infoWindow = new google.maps.InfoWindow({
                    content: j[i].name
                });
                
                // Create marker                
                map.addMarker({
                    icon: "/assets/img/s2.png",
        			lat: j[i].loc[0],
        			lng: j[i].loc[1],
                    animation: google.maps.Animation.DROP, 
                    infoWindow: {
                      content: '<p>'+j[i].name+'</p>'
                    }      			 
                });                 
            }
            
            for(var i in map.markers){
                (map.markers[i].infoWindow).open(map.map,map.markers[i]);
            }

Leave a Reply