2011-07-21 69 views
1

我有一个安装程序,其中存在多个标记,每个标记在点击时加载到单个InfoWindow。Google Maps API v3 - 当点击标记时点击事件不会触发另一个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)); 
    } 
} 

回答

0

退房这里我的答案:

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

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

鲍勃

+0

感谢鲍勃。尽管如此,我还是从ajax调用回来了内容。我已经尝试了一系列infoWindows,没有运气。这是你推荐的关键部分吗? – evanmcd

+0

好的,实际上帮助修复的部分是每次创建htmlContent,而不是操纵现有元素。示例:https://gist.github.com/1099679 – evanmcd

相关问题