Based on a selected country and date a list of results will show up on the map. The placements of markers with html data in them works fine, the problem I have is handling the cases with duplicate markers.

I found a way to check for duplicate ones, but I would like to be able to modify the content in the infowindow of the one already present. So that I can add the content of the duplicate marker to the existing marker that stands in the same location.

The problem I'm having is that I can't find the right way to access the data in the existing infowindow for the duplicate one.

If I do alert(infoWindow.getContent());, then I just get "undefined". I also tried markers[i].getContent(), but that also didn't do anything.

Any idea's, or suggestion on how I can access the infowindows of previously added markers, get their content with getContent(), and add the data of the duplicate one to it?

Code:
    
    var marker = new google.maps.Marker({
        map: map,
        position: latlng
    });
    
    for (var i=0; i<markers.length; i++) {
        if (markers[i].getPosition().equals(marker.getPosition())) {
            alert('duplicate found');
            alert(infoWindow.getContent());
            
        } else {
            google.maps.event.addListener(marker, 'click', function() {
                infoWindow.setContent(html);
                infoWindow.open(map, marker);
            });
        }
    }