谷歌地图API错误:" initMap不是一个功能"

时间:2016-11-27 09:39:10

标签: javascript html twitter-bootstrap google-maps

我收到了Google Maps API错误:if (isset($_COOKIE['cookie'])) { unset($_COOKIE['cookie']); setcookie('cookie', '', time() - 3600, '/'); // empty value and old timestamp } 。奇怪的是,我的地图在我的本地测试中工作正常,然后我将其上传到我的网站并得到了错误。现在它也没有在我的本地机器上工作。发生了什么事?

HTML

initMap is not a function
<div class="row">
    <div class="container-fluid">
        <div id="map"
             class="hidden-xs hidden-sm" 
             style="width:101%;height:400px;background:yellow">
        </div>
    </div>      
</div>

1 个答案:

答案 0 :(得分:1)

尝试同样提供async=""属性。它有效:

function myMap() {
  var myCenter = new google.maps.LatLng(40.488158, -85.615340);
  var mapCanvas = document.getElementById("map");
  var mapOptions = {
    center: myCenter,
    zoom: 18
  };
  var map = new google.maps.Map(mapCanvas, mapOptions);
  var marker = new google.maps.Marker({
    position: myCenter,
    icon: 'img/smally.png',
    animation: google.maps.Animation.BOUNCE
  });

  marker.setMap(map);
}
<script src="https://maps.googleapis.com/maps/api/js?callback=myMap" async="" defer=""></script>

<div class="row">
  <div class="container-fluid">
    <div id="map" class="hidden-xs hidden-sm" style="width:101%;height:400px;background:yellow">
    </div>
  </div>
</div>