2012-12-13 74 views
1


我使用的版本是3.8 沒有的一個關鍵。我在桌面之前(沒有鍵)使用了這個確切的代碼,它工作得很好,但現在由於某種原因,它不工作。

我找不到任何拼寫錯誤,導入聲明時沒有更改我使用的密鑰?

這裏是我的精簡代碼:
這個簡單的Google地圖代碼爲什麼不起作用?

<!DOCTYPE html> 
<html> 
    <head> 
     <title>asdfasdf</title> 
    </head> 
    <body onload = "initialize();"> 

     <!-- map here --> 
     <div id = "map"></div> 

     <!-- Google Maps API --> 
     <script type = "text/javascript" src = "http://maps.googleapis.com/maps/api/js?&amp;sensor=true&amp;v=3.8"></script> 

     <script type = "text/javascript"> 

      function initialize() 
      { 
       // object literal for map options 
       var myOptions = 
       { 
        center: new google.maps.LatLng(37.09024, -95.712891), // coordinates for center of map 30, 3 
        zoom: 4, // smaller number --> zoom out 
        mapTypeId: google.maps.MapTypeId.HYBRID // ROADMAP, SATELLITE, TERRAIN, or HYBRID 
       }; 

       // note: if the id has a dash in its' name, map instantiation doesn't work! 
       var map = new google.maps.Map(document.getElementById("map"), myOptions); 

      } // end of initialize 
     </script> 
    </body> 
</html> 
+0

更改http://maps.googleapis.com/maps/api/js? & sensor = true & v = 3.8 to http://maps.googleapis.com/maps/api/js?&sensor=true&v=3.8 – Kotzilla

回答

2

它的工作。也許你忘了給你地圖div width/height,所以你看不到它?

,你可以看看這裏http://jsfiddle.net/2HmMQ/

+0

哈哈,完全正確!杜,我不能相信我錯過了那個,有時我真的被困在簡單的事情上。感謝您的幫助。 –

2

V3.8 is retired,如果你要求它,你會得到V3.9。

你的問題是你的地圖沒有尺寸,所以你看不到它。

如果我更改地圖div來給它的大小,這樣的事情:

 <div id="map" style="height:500px; width:600px;"></div> 

它的工作原理。

+0

啊v3.9現在,感謝您的信息。 –

相關問題