2013-11-04 55 views
-2

我嘗試在單頁上顯示多個自定義谷歌地圖,但是當一個人顯示,另一種被竊聽,你可以看到如下:enter image description here多谷歌地圖的bug

我不喜歡它來自我的代碼,因爲兩個容器都符合正確尺寸(並且Google徽標和「使用條款」已正確顯示)。但是,「地圖圖塊」不會顯示在第二張地圖中,而是應用灰色背景。

任何想法/建議?

編輯:第一張地圖似乎總是顯示,其他人總是被竊聽。

+1

你能分享一些代碼。這在每個瀏覽器上都是這樣嗎? – Regu

+0

第二張地圖看起來是地圖在他們需要調用大小調用函數時的樣子。 – Andy

+0

嗯。我希望這是一個已知的錯誤。這個例子來自Chrome,也發生在Firefox上。實際上,這並不是每次都發生,有時第二次被竊聽,但不是第一次......我使用json-p加載地圖數據,所以我想它是「先來先服務」。並且顯示代碼非常棘手,因爲有許多方法的文件很多......我會試着找出一些東西。 – Simon

回答

0

我終於找到了如何解決我的問題,這是@ Andy的解決方案和我的混合。該resize事件的確應該被觸發,但是縮放級別和地圖中心顯示不正常,你可以看到如下:

enter image description here

要更新縮放級別和中心,我用這個首頁製作方法,它更新我的地圖取決於地圖標記的範圍:

var updateBounds = function (map, markers) { 
    var bounds = new google.maps.LatLngBounds(); 

    for (var i = 0, len = markers.length ; i < len ; i++) { 
     bounds.extend (markers[i].marker.position); 
    } 

    // extend bounds using two invisible markers so the markers don't get too close to the map borders 
    var 
     extendPoint1 = new google.maps.LatLng (bounds.getNorthEast().lat() + 0.001, bounds.getNorthEast().lng() + 0.001), 
     extendPoint2 = new google.maps.LatLng (bounds.getNorthEast().lat() - 0.001, bounds.getNorthEast().lng() - 0.001); 

    bounds.extend (extendPoint1); 
    bounds.extend (extendPoint2); 

    map.fitBounds (bounds); 
}; 
0

google.maps.event.trigger(secondmap, 'resize');去看看會發生什麼。

+0

我發現你自己的答案附近有一些糖:http://stackoverflow.com/questions/17059816/google-maps-v3-load-partially-on-top-left-corner-resize-event-does-not-工作 另一個在這裏: http://blog.codebusters.pl/en/entry/google-maps-in-hidden-div 但儘管它似乎符合我的問題,但它並沒有解決它。我仍然有這個問題。 – Simon