【问题标题】:Focus a responsive Google Map?专注于响应式谷歌地图?
【发布时间】:2017-05-17 19:50:41
【问题描述】:

我查看了SO 并在实际问题中实现了答案。

但得到错误:

Uncaught ReferenceError: google is not defined

我通过嵌入 iframe 来添加我的地图,而且我的 JS 直到

才运行
$(document).ready(function(){

那么我哪里错了?

【问题讨论】:

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


    【解决方案1】:

    我认为谷歌之前检查过你的 APIKEY。

    尝试documentation 中描述的方法,在 scrips 标签内传递回调;)

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

    【讨论】:

    • 与问题无关。
    • 当我试图帮助你时,我建议你正确阅读。如果您的 google 对象为空,那是因为您的脚本尚未准备好,这确保 google 已准备好...
    • 但我不是通过脚本嵌入的,我建议您正确阅读问题。
    • 在这种情况下,我们在您的问题中没有足够的详细信息。如果不包含 API,为什么还要尝试使用 API?
    猜你喜欢
    • 2014-02-02
    • 2013-03-03
    • 2018-02-05
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    相关资源
    最近更新 更多