Multiple “InfoWindow” for array of “markers” on Google Maps?

后端 未结 1 1743
星月不相逢
星月不相逢 2020-12-22 13:46

Using Google Maps API to add an infoWindow to each marker. Markers come from an array.

Although, infoWindow only shows up for the first marker, not the others. Why?

1条回答
  •  萌比男神i
    2020-12-22 14:07

    var infowindow = new google.maps.InfoWindow();
    
    function set_markers(array) {
    
        var mapOptions = {
            zoom: 13
        };
    
        for (var i = 0; i < array.length; i++) {
    
            var single_location = array[i];
            var myLatLng = new google.maps.LatLng(single_location[1], single_location[2]);
            var marker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                title: single_location[0]
            });
    
            google.maps.event.addListener(marker, 'click', function () {
                infowindow.setContent('

    ' + this.title + '

    '); infowindow.open(map, this); }); } }

    This is untested since you didn't post a MCVE.

    0 讨论(0)
提交回复
热议问题