1

我有一个设置,其中存在多个标记,每个标记在单击时将内容加载到单个信息窗口。

不幸的是,当另一个窗口打开时,似乎没有触发标记的点击事件。

这似乎是一种奇怪的行为。有没有其他人发现是这种情况?

谢谢

我的代码如下:

var infoWindow  = new google.maps.InfoWindow();

if(markers) {
    var length = markers.length;
    for(var i = 0; i < length; i++) {
        var details = markers[i];
        markers[i] = new google.maps.Marker({
            title: details.name,
            position: new google.maps.LatLng(details.location[0],details.location[1]),
            locCode: details.locCode
        });
        markers[i].setMap(map);
        var thisMarker = markers[i];
        google.maps.event.addListener(thisMarker, 'click', (function(thisMarker, i, details) {
            // self calling function was the key to get this to work
            return function() {
                $.ajax({
                    url: 'js/locations/'+details.locCode+'.js',
                    dataType: 'script',
                    success: function(data) {
                        // do my specific stuff here, basically adding html to the info-window div via jQuery

                        // set the content, and open the info window
                        infoWindow.setContent($("#info-window").html());
                        infoWindow.open(map, thisMarker);
                    }
                });
            }
          })(thisMarker, i, details));
    }
}
4

1 回答 1

0

在这里查看我的答案:

Jquery Google Maps V3 - 信息窗口始终固定在一个标记上

我认为这将有助于解决您的问题。

鲍勃

于 2011-07-21T21:25:26.403 回答