Multiple Google Maps infowindow

后端 未结 2 741
臣服心动
臣服心动 2020-12-03 12:45

Current I have a google maps that will display some markers on the map from my DB... I would like to add a infowindow when the users click on the marker.

I got it to

2条回答
  •  难免孤独
    2020-12-03 13:28

    I've also stumbled across this problem.

    Here's how I fixed it:

    I used a function to bind a marker to an infowindow.

    var marker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                icon: image,
                title: office[0],
                zIndex: office[3]
            });
    
    var contentString = "Hello!!!";
    var infowindow = new google.maps.InfoWindow;
    
    bindInfoW(marker, contentString, infowindow);
    
    }
    
    function bindInfoW(marker, contentString, infowindow)
    {
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.setContent(contentString);
                infowindow.open(map, marker);
            });
    }
    

提交回复
热议问题