2011-07-21 39 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

相關問題