Google Maps API v3 adding an InfoWindow to each marker

前端 未结 9 553
刺人心
刺人心 2020-11-29 21:36

NOTE: I\'m using v3 of the Google Maps API

I\'m trying to add an info window to each marker I put on the map. Currently I\'m doing this with the following code:

9条回答
  •  日久生厌
    2020-11-29 22:08

    for Earth plugin APIs, create the balloon outside your loop and pass your counter to the function to get unique contents for each placemark!

    function createBalloon(placemark, i, event) {
                var p = placemark;
                var j = i;
                google.earth.addEventListener(p, 'click', function (event) {
                        // prevent the default balloon from popping up
                        event.preventDefault();
                        var balloon = ge.createHtmlStringBalloon('');
                        balloon.setFeature(event.getTarget());
    
                        balloon.setContentString('iframePath#' + j);
    
                        ge.setBalloon(balloon);
                });
            }
    

提交回复
热议问题