2011-10-26 25 views
2

我在我的網頁下面的代碼 - 地圖div沒有顯示在谷歌地圖,但我找不到什麼毛病代碼:谷歌地圖API的Javascript - 不顯示地圖

$mapCode = "<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=$google_maps_apiKey\" type=\"text/javascript\"></script> 
    <div id=\"map_canvas\" style=\"width: 500px; height: 500px\"></div> 
<script type=\"text/javascript\"> 
    function showAddress(address) { 
     var map = new GMap2(document.getElementById('map_canvas')); 
     alert(\" not found\"); 
     var geocoder = new GClientGeocoder(); 
     geocoder.getLatLng(
     address, 
       function(point) { 
        if (!point) { 
         alert(address + \" not found\"); 
        } else { 
         map.setCenter(point, 13); 

         var marker = new GMarker(point); 
         map.addOverlay(marker); 
        } 
       } 
      ); 
      } 
showAddress(\"$address\"); 
</script>"; 

echo $mapCode; 

任何幫助非常感謝。由於

+0

我得到一個'未找到'警報。這是問題嗎? –

+0

我發現問題,檢查了螢火蟲控制檯,在map.setCenter行 – EI756

回答

14

我剛剛纔通過物理告訴它的高度工作....在我的CSS我把:

#map_canvas { 
    height:100px; margin: 0; padding: 0; 
} 

,而不是

#map_canvas { 
    height:100%; margin: 0; padding: 0; 
} 

不知道爲什麼它沒原本的工作...

+0

有一個小錯誤,這是有益的.. – CodeMonkey

+0

這解決了我的prb太謝謝@matt – anonymous5671

+1

您的先生,真棒! –