繁体   English   中英

使用Google Maps API时地图不显示

[英]Map not showing when using Google Maps API

我正在尝试使用Google Maps API来显示一张地图。 我正在使用Javascript。

它应该是一个页面,其中包含一个标题,并且在标题下方有一个地图。 我最近注册了Google Maps API,所以不确定该API密钥是否需要花费一定的时间才能激活。 我还有其他CSS文件和一个googlemaps.js文件,其中还没有任何内容。

这是我的代码。 任何想法为什么它不起作用?

<!doctype html>
<html>
<head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, intial-scale=1.0;'>
    <title>API(s)</title>
    <link rel='stylesheet' href='styles/semantic.min.css'>
    <link rel='stylesheet' href='styles/main.css'>

</head>

<body>

    <div class="ui two column centered stackable grid container">
        <div class="column">
            <h1 class="goog-header">Location Based Image Search</h1>
        </div>
    </div>

    <div class="ui one column stackable grid container js-images-container">
        <div class="column">
            <div id="map"></div>
        </div>
    </div>

    <script>
      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -34.397, lng: 150.644},
          zoom: 8
        });
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCXTmorapOu1WquB3VlsLrckhE45Bgfrfw&callback=initMap" async defer></script>

<script src='javascript/googlemaps.js'></script>    
</body>
</html>

尝试将地图DIV更改为:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM