Adding multiple markers with infowindows (Google Maps API)

后端 未结 6 1186
别跟我提以往
别跟我提以往 2020-11-29 17:28

I\'m currently using the following code the place multiple markers on a Google Map using their API.

The problem I\'m having is with multiple infowindows not working

6条回答
  •  迷失自我
    2020-11-29 18:10

    This works fine for me! Just add a new property to marker object, this property contains the infowindow object.

    var mytext = 'Infowindow contents in HTML'
    var myinfowindow = new google.maps.InfoWindow({
        content: mytext
    });
    
    var marker = new google.maps.Marker({
        position: mypos,
        map: mymap,
        icon: myicon,
        title: mytitle,
        infowindow: myinfowindow
    });
    
    google.maps.event.addListener(marker, 'click', function() {
            this.infowindow.open(map, this);
    
    });
    

提交回复
热议问题