Google Maps API Multiple Markers with Infowindows

前端 未结 5 1667
挽巷
挽巷 2020-11-30 17:45

I am trying to add multiple markers each with its own infowindow that comes up when clicked on. I am having trouble with getting the infowindows coming up, when I try it eit

5条回答
  •  盖世英雄少女心
    2020-11-30 18:15

    You could use a closure. Just modify your code like this:

    google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){ 
        return function() {
            infowindow.setContent(content);
            infowindow.open(map,marker);
        };
    })(marker,content,infowindow));  
    

    Here is the DEMO

提交回复
热议问题