2013-05-18 114 views
0

我试图运行一个简单的谷歌地图示例(这是例子:https://developers.google.com/maps/documentation/javascript/examples/map-simple-async)。我把代码放在我的.hmtl文件中,但是我得到一个空白页面。当然,这似乎发生在所有的谷歌示例(我保存所有的文件在ANSI格式)。谷歌地图示例不工作

的代码是:

<!DOCTYPE html> <html> <head> 

<title>Asynchronous Loading</title> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
<meta charset="utf-8"> 
<script> 
    function initialize() 
    { 
     var mapOptions = { 
      zoom: 8, 
      center: new google.maps.LatLng(-34.397, 150.644), 
      mapTypeId: google.maps.MapTypeId.ROADMAP}; 

     var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 
    } 

    function loadScript() 
    { 
     var script = document.createElement('script'); 
     script.type = 'text/javascript'; 
     script.src = 'http://maps.googleapis.com/maps/api/js?key=<MY_CODE>&sensor=false&callback=initialize'; 
     document.body.appendChild(script); 
    } 

    window.onload = loadScript; 

</script> </head> <body> 
<div id="map-canvas"></div> </body> </html> 
+0

您在URL中的API指定键=,但你不要打扰把一个值吧:

看他们的CSS文件,你需要类似的东西。或者添加一个键值,或者如果您不使用键值,则不要在URL中键入键值。 – duncan

+0

你是否需要异步加载地图文件?如果没有,还有更简单的方法来做到这一点,而不使用回调 – duncan

+0

我把钥匙放在那里。这只是一个例子,但对于我的allexamples似乎只显示一个空白页:(我也尝试从头部加载JS ...相同的行为。 – Larry

回答