Google Maps API v3 - 当另一个信息窗口打开时单击标记时,单击事件不会触发

发布于 2024-11-25 15:50:29 字数 1420 浏览 0 评论 0原文

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

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

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

谢谢

我的代码如下:

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));
    }
}

I've got a setup in which multiple markers present, each loading in content to a single InfoWindow when it's clicked.

Unfortunately, it seems that the marker's click event is not being fired when it's clicked while another window is open.

This seems like an odd behavior. Has anyone else found this to be the case?

Thanks

My code below:

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));
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴者 2024-12-02 15:50:29

在这里查看我的答案:

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

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

鲍勃

Check out my answer here:

Jquery Google Maps V3 - Information window is always fixed to one marker

I think this will help resolve your issue.

Bob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文