2013-04-27 116 views
0

我正在關注Google的這個tutorial關於如何在html頁面中使用簡單的地圖。但是,當我運行代碼時,只顯示一個灰色方塊(我創建的div)。任何人都可以幫我嗎?Google Maps API - 地圖不顯示

這裏是我使用的代碼:

<!DOCTYPE html> 
<html> 
    <head> 
     <style> 
      #map_canvas { 
       width: 500px; 
       height: 500px; 
       background-color: #CCC; 
      } 
     </style> 
     <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
     <script> 
      function initialize() { 
       var ap_canvas = document.getComputedStyle('map_canvas'); 
       var mapOptions = { new google.maps.Lating(44.5403, -78.5463), 
        zoom:8, 
        mapTypeld: google.maps.MapTypeId.ROADMAP } 
        var map = new google.maps.Map(map_canvas, mapOptions) 
        } 
      google.maps.event.addDomListener(window, 'load', initialize); 
     </script> 
    </head> 
    <body> 
     <div id="map_canvas"> 

     </div> 

    </body> 
</html> 

回答

1

你有幾個錯別字,比如 「VAR ap_canvas」 應該是 「無功map_canvas」 的。此功能有效:

<script> 
function initialize() { 
    var map_canvas = document.getElementById('map_canvas'); 
    var map_options = { 
    center: new google.maps.LatLng(44.5403, -78.5463), 
    zoom: 8, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
} 
var map = new google.maps.Map(map_canvas, map_options) 
} 
google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
+0

謝謝!有效 – 2013-04-27 15:43:27