2014-11-06 186 views
0

我有一個網站http://arquitectospelomundo.com,它顯示了幾個標記,由markerclusterer函數組合,當點擊時顯示一個帶有一些信息的信息窗口。當直接點擊地圖時,信息窗口出現在右側;但是當點擊側邊欄(在其中一張圖片上)時,信息窗口會超出界限。 這是正常工作,並突然改變;我試圖弄清楚,但迄今爲止沒有成功。我將不勝感激任何幫助,指引我朝着正確的方向前進。 謝謝。谷歌地圖infoWindow的定位錯誤

+0

請發表[最小的,完整的,經過測試和讀示例](http://stackoverflow.com/help/mcve)在問題本身,而不僅僅是一個鏈接到一個問題網站。 – geocodezip 2014-11-06 23:46:11

+0

感謝您的免責聲明鏈接。我會在下次嘗試更準確。 – BMM 2014-11-07 17:07:27

回答

1

看起來問題與MarkerClusterer有關。

當觸發點擊的標記位於羣集內時,標記的map-property爲null,您得到的位置不正確。

可能的解決方案:

當標記在羣集內使用隱藏標記(經由visible隱藏)作爲錨信息窗口:

google.maps.event.addListener(marker, 'click', function() { 
    //create the dummy-marker on first click 
    if(!map.get('dummy')){ 
    map.set('dummy',new google.maps.Marker({map:map,visible:false})) 
    } 
    var latLng = marker.getPosition(); 

    //when the marker is within a cluster 
    if(!marker.getMap()){ 
    //set position of the dummy 
    map.get('dummy').setPosition(latLng); 
    //use dummy as infowindow-anchor 
    marker= map.get('dummy'); 
    } 
    map.panTo(latLng); 
    infowindow.setContent(contentString); 
    infowindow.open(map,marker); 

}); 
+0

非常感謝您的解決方案。我不知道爲什麼會發生這種情況,因爲它在幾天前正在工作!但是這個代碼解決了這個問題。再次感謝。 – BMM 2014-11-07 17:06:49

0

我與標記聚類器和外同樣的問題點擊地圖,打開infowindows。 @ Dr.Molle帶有虛擬標記的解決方案是一個不錯的方向,但問題是您可以使用虛擬來平移,但是監聽器觸發不在地圖上的標記點擊。正確的infowindow會打開,但自動滾屏功能無法知道要在哪裏平移,因此它保留在最後一次點擊之後的位置。這是地圖外部重複點擊造成的問題。第一次點擊沒問題,但第二次或第三次出現錯誤,取決於它是否在羣集中。

我找到的解決方案是測試標記是否在集羣中,如果是,則將其附加到地圖上,並在點擊後將其刪除(不確定是否需要,可能爲了防止地圖變慢)。我把它放在每次點擊從外面調用的函數中。但也許你也可以將它構建到事件監聽器中。這完美的作品對我來說:

function openInfoWindow(id){ 

    googlemap.setZoom(13); 
    var marker = markers[id]; 
    var latLng = marker.getPosition(); 

    if(!marker.getMap()){ //if the clicked marker is in a cluster, so it is not attached to a map 

     marker.setMap(googlemap); //attach it to the map 
     google.maps.event.trigger(marker, 'click'); // the standard trigger, opens infowindow 
     googlemap.panTo(latLng); 
     marker.setMap(null); //detach it from the map (not sure if necessary 

    } else { 

     google.maps.event.trigger(marker, 'click'); 
     googlemap.panTo(latLng); 

    } 

    return false; 
}