【问题标题】:Google Maps API Example not working, giving me blank screenGoogle Maps API 示例不起作用,给我空白屏幕
【发布时间】:2013-08-13 05:10:22
【问题描述】:

Google Maps API 教程 (https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map) 给了我一个空白屏幕。我已经为此工作了 3 个小时,但无法弄清楚。

我什至完全复制/粘贴了代码,它被保存为 .html 文件。

<!DOCTYPE html>
<html>
  <head>
    <style>
      #map_canvas{
        height: 500px;
        width: 400px;
      }
    </style>
    <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <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>
  </head>

  <body>
    <div id="map_canvas"></div>
  </body>
</html>

【问题讨论】:

    标签: html css google-maps google-chrome


    【解决方案1】:

    您的代码中有非法字符:

    Timestamp: 08/12/2013 02:08:39 PM
    Error: illegal character
    Line: 21, Column: 48
    Source Code:
       google.maps.event.addDomListener(window, $(B!F(Bload$(B!G(B, initialize); 
    

    变化:

     google.maps.event.addDomListener(window, ‘load’, initialize);
    

    收件人:

     google.maps.event.addDomListener(window, "load", initialize);
    

    【讨论】:

      【解决方案2】:

      您需要将&amp;callback=initialize 添加到您的网址中,该额外参数告诉Google 这是要调用的函数。该函数必须可从 window 范围访问。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-12
        • 2012-11-25
        • 2013-05-21
        • 2021-12-04
        • 2018-04-25
        • 1970-01-01
        • 1970-01-01
        • 2018-06-17
        相关资源
        最近更新 更多