InvalidValueError:initAutocomplete 不是 Google Places 和 Autoco
InvalidValueError: initAutocomplete is not a function Google Places and Autocomplete API
希望你能帮上忙,因为我碰壁了,我对使用谷歌的地方API也很陌生。
我暂时不打算发布任何代码,因为当我即将描述的 2 个部分单独运行时,我的代码工作正常。
除了使用Google提供的Javascript示例的Autocomplete API之外,我还使用Google的Places。
最初,我在文档底部有以下脚本:
<script src="https://maps.googleapis.com/maps/api/js?&libraries=places&callback=initAutocomplete" async defer></script>
我的文档顶部的这个脚本:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
这给了我,"你在这个页面上多次包含了谷歌地图API。这可能会导致意外错误。 所以在研究之后,我像这样将两者合并在一起:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&callback=initAutocomplete&sensor=false"></script>
但是,现在我已经完成了此操作,我收到以下错误:
InvalidValueError: initAutocomplete is not a function
TypeError: searchBox is undefined
当这些脚本未合并时,我没有收到这些错误,但后来我意识到需要 Places API 的函数停止工作。如果我删除自动完成 API 引用,则位置函数将起作用。
关于我如何使这两者协同工作,如图所示合并它们并解决"非函数"问题的任何想法?
任何建议将不胜感激,如果您真的需要查看代码,请告诉我。
提前感谢,斯蒂芬
你应该只使用一次包含脚本,比如:
//maps.googleapis.com/maps/api/js?key=__API-KEY__&libraries=places
请注意,在包含脚本时省略了"回调"参数。然后在窗口加载时加载 initAutocomplete,如下所示:
google.maps.event.addDomListener(window, 'load', initAutocomplete);
也许您需要在头部中包含gmaps脚本,或者如果您将js内联放置,则会收到"google未定义"错误。
刚刚尝试了这个,发现删除 asyc
属性可以解决这个问题。即使在 Google API URL 上使用地点的回调也是如此。
删除 async
属性是一个较小的修复。
只需从查询中删除&callback=initAutocomplete
,并在加载所有内容时在脚本中调用它。
相关文章:
- 在自动完成中使用Google Maps Places API;API不工作
- 从Chrome扩展加载Places API库
- 带有新API密钥的Google Places Library OVER_QUERY_LMIT
- Google Places API显示雷达搜索中的位置图标/图像
- 如何使用Google Places Javascript API搜索附近的位置(自动从浏览器获取坐标)
- InvalidValueError:initAutocomplete 不是 Google Places 和 Autoco
- 如何使用地点ID从Google Places JS API检索地点详细信息
- 在Google Places API中为每个位置类型单独标记
- 将Google Places API与Rails应用程序集成
- 当至少有20个搜索结果时,只呈现10个搜索结果?使用Google Places API
- 如何使用带有搜索按钮的Google Places API
- 如何使用promise获取Google Places数据
- Google Places Library Replacement for google.maps.LocalSearc
- 如何检测用户何时在Google Places字段中输入无效位置
- Rails-jQuery地理编码和Places自动完成插件不起作用
- 如何使用Google Places API获取邮政编码
- 如何在模板中加载和访问Google Places库
- “;位置搜索框”;在Google Places API中
- Ajax and Google Places API getting json
- Google Places API,结果的附加标记(手动添加)