Google Maps - Multiple markers - 1 InfoWindow problem

后端 未结 5 884
一整个雨季
一整个雨季 2020-12-09 23:18

I can\'t get my markers to display different infowindows. The markers always display the content of the last \"contentString\".

I\'ve read a few other posts but none

5条回答
  •  渐次进展
    2020-12-10 00:19

    Im having the same problem. I was able to get the title show up different though using this code:

      setMarkers(map, airports);
     }
    
     function setMarkers(map, locations) 
       {
         //you only need 1 infoWindow
         var infowindow = new google.maps.InfoWindow({
           content: "holding" //content will be set later
         });
    
         for (var i = 0; i < locations.length; i++) 
         {
           var airport = locations[i];
           var myLatLng = new google.maps.LatLng(airport[1], airport[2]);
           var marker = new google.maps.Marker({
                 position: myLatLng,
                 map: map,
                title: airport[0],
                zIndex: airport[3],
                 html: airport[4],
          });
    
    
    
    
           google.maps.event.addListener(marker, 'click', function() {
                   infowindow.setContent(this.html);//set the content
                   infowindow.open(map,this);
           });
         }
       }
    

提交回复
热议问题