【问题标题】:Google map getting "initMap is not a function" in chrome browser only谷歌地图仅在 Chrome 浏览器中获取“initMap 不是函数”
【发布时间】:2019-12-14 19:30:57
【问题描述】:

Google 地图仅在 chrome 浏览器中获取“initMap 不是函数”。

在其他浏览器(Firefox、IE 等)中运行良好。

我正在使用 Google MAP API 进行位置搜索和自动完成位置。

我尝试过的类似问题的答案。 (https://stackoverflow.com/questions/46319676/initmap-is-not-a-function-in-using-google-maps-api),(https://stackoverflow.com/questions/40448238/initmap-is-not-a-function) 尚未在 Chrome 中运行。

这里是代码。

<script>function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
    center: { lat: 34.397, lng: 150.644 },
    scrollwheel: false,
    zoom: 2
});
}    
</script>

<script async defer
            src="https://maps.googleapis.com/maps/api/js?key={{KEY}}&callback=initMap">
    </script>
<div>
  <div id="map" style="width: 500px; height: 400px;"></div>
</div>

【问题讨论】:

标签: javascript html google-maps google-chrome google-maps-api-3


【解决方案1】:

脚本应该在下面的部分。它找不到“地图” div,因此会产生导致“initMap 不是函数”问题的问题。

<html>
<head></head>
<body>
<div>
  <div id="map" style="width: 500px; height: 400px;"></div>
</div>

<script>
    // scripts goes here
</script>
<script async defer
            src="https://maps.googleapis.com/maps/api/js?key={{KEY}}&callback=initMap">
    </script>
</body>
</html>

【讨论】:

    【解决方案2】:

    使用这个

    <script
    src="http://maps.googleapis.com/maps/api/js?v=3&amp;sensor=false"></script>
    $(document).ready(function() {
        ...
        google.maps.event.addDomListener(window, 'load', initMap);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      相关资源
      最近更新 更多