HTML页面无法显示谷歌地图。

3

我有一个简单的HTML页面,我想使用API Access显示谷歌地图。我使用以下代码:

    <!DOCTYPE html><!-- HTML5 -->
<html lang="it" dir="ltr">
    <head>
        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=blablabla&sensor=true">
        </script>
        <script type="text/javascript">
          function initialize() {
            var mapOptions = {center: new google.maps.LatLng(-34.397, 150.644), zoom: 8};
            var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
          }
          google.maps.event.addDomListener(window, 'load', initialize);
        </script>
    </head>
    <body>
        <div id="map-canvas"/>
    </body>
</html>

我确定脚本块已经被处理了,但页面上没有显示地图。
你能帮我吗?
2个回答

3

//在head部分放置以下样式

<head>
<style>
  html{
    height:100%;
   }
   body{
    margin: 0;
    padding: 0;
    height:100%;
   }
</style>
</head>

//在你的文档中,定义map_canvas的样式如下:

<body>
 <div id="map_canvas" style="height:100%;"></div>

</body>

//右键单击文档,并选择检查元素。在开发者工具中选择控制台选项卡。如果没有显示错误,则可能会解决您的问题 //祝你好运 8-)


问题出在样式上!谢谢。但现在不要显示传感器 :( - Daniele

0

试一下

首先在您的 <head> 部分中包含 Jquery 库(在 Google JS 文件之前)

<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接