【问题标题】:google.maps.places and its Autocomplete method are undefinedgoogle.maps.places 及其 Autocomplete 方法未定义
【发布时间】:2013-09-24 20:47:58
【问题描述】:

我正在加载Google Maps APIjQuery 和这个Geocomplete 插件。 请注意,我还指定了库 (libraries=places) 并最终指定了我的 API 密钥

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script src='http://maps.googleapis.com/maps/api/js?v=3&sensor=false&amp;libraries=places&key=xxx'></script>
<script src='js/vendor/jquery.geocomplete.js'></script>

我在页面加载时触发 Geocomplete 插件

$(window).load(function () {
    $('#my-input').geocomplete();
});

但我总是收到错误:

Uncaught TypeError: Cannot read property 'Autocomplete' of undefined [jquery.geocomplete.js:153]

插件内部...

this.autocomplete = new google.maps.places.Autocomplete(
 this.input, options
);

我尝试 google.maps 并返回一个常规对象,但地点是 未定义

【问题讨论】:

    标签: javascript jquery google-maps


    【解决方案1】:

    我尝试 google.maps 并返回一个常规对象,但地点未定义!

    这意味着 google.maps.places 库未加载(您发布的代码行如下所示不正确或实际上不在您的页面上):

    <script src='http://maps.googleapis.com/maps/api/js?v=3&sensor=false&amp;libraries=places&key=xxx'></script>
    

    这是文档中的示例:

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
    

    唯一明显的区别是您的&amp;amp;,它应该可以工作,但您可能应该始终如一地使用它。

    TL;DR

    使用&amp;amp;libraries 而不是&amp;amp;libraries,它会起作用。

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      相关资源
      最近更新 更多