Multiple Google Maps infowindow

后端 未结 2 716
臣服心动
臣服心动 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:14

    http://www.codefx.biz/2011/01/google-maps-api-v3-multiple-infowindows

    this way also works!

    0 讨论(0)
  • 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);
            });
    }
    
    0 讨论(0)
提交回复
热议问题