首页 文章

Google Maps Places API:TypeError:自动完成未定义

提问于
浏览
0

每当我尝试使用Google Maps API地方库时,它会在我的浏览器控制台中显示此错误:

TypeError: autocomplete is undefined

如果我'm not mistaken, that means the places library couldn'吨加载 . 至于代码,我有自己的代码,但我也复制了Places API教程(https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform)中的代码 .

在我的 Headers 中,我有两行包括:

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

我还确保在我的Google API控制台中启用了Placis API,Google Maps JavaScript API v3和Google Maps Geolocation API .

我不太确定问题是什么,除了地方库没有加载 . 我应该注意到我正在研究隐藏的子域,这可能是问题吗?

提前致谢 .

1 回答

  • 1

    请确保您只加载一次maps文件(并且您应该始终通过https或使用活动protocl加载api):

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

    子域不应该是一个问题,所以你可以使用它 .

相关问题