我想顯示谷歌地圖到Twitter引導模式。 當用戶第一次點擊按鈕Show map
時,他能夠成功地看到地圖,因爲我正在生成地圖onclick()
函數,但是當他關閉模式並重新打開它時,地圖不能正確顯示,並且地圖的90%部分變灰像下面谷歌地圖模式問題
我甚至嘗試這種解決方法是刪除整個DIV在地圖上被綁定,並重新生成它,但是招亙古不變的工作也請讓我知道我可以解決我的問題。
下面是我打電話的onclick顯示地圖的情況下
function mapp()
{
//google.maps.event.trigger(map, "resize");
//$("#map_google_canvas").empty();
$("#map_google_canvas").remove();
$("#crmap").append("<div id='map_google_canvas'></div>")
var myOptions = {
center: new google.maps.LatLng(54, -2),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_google_canvas"), myOptions);
var addressArray = new Array("London, United Kingdom", "London Road, Brentwood, United Kingdom", "Brentwood, United Kingdom");
var geocoder = new google.maps.Geocoder();
var markerBounds = new google.maps.LatLngBounds();
for (var i = 0; i < addressArray.length; i++) {
geocoder.geocode({
'address': addressArray[i]
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
markerBounds.extend(results[0].geometry.location);
map.fitBounds(markerBounds);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
請幫助我的js函數,
感謝
這是完全正常和預期的行爲,我很難說。結合在隱藏 - >展示 - >隱藏元素上展示他們,Google地圖會出現許多頁面「混亂」。此外,谷歌地圖不會每次都搞砸,它只是最有可能的。唯一的解決方案是在容器被設置爲show/visible之前重新生成地圖,這裏是引導模式。當然,您只需運行一次'addressArray'循環,並將地理編碼結果存儲在查找表中。 – davidkonrad
問題正在從以下問題解決:http://stackoverflow.com/questions/8812268/grey-boxes-appear-in-parts-of-embedded-google-map-in-modal-box?rq = 1 –
酷! Didnt知道調整大小的觸發器。它可以在未來幫助很多!已經提出了你的問題和你找到的答案。謝謝! – davidkonrad