gpt4 book ai didi

angularjs - 类型错误 : window. initMap 不是函数

转载 作者:行者123 更新时间:2023-12-02 23:04:34 24 4
gpt4 key购买 nike

我正在按照这个教程,基本上复制所有代码

https://developers.google.com/maps/documentation/javascript/tutorial

但出现错误,指出 initMap 函数不是函数。我在我的项目中使用 angularjs,这会导致问题吗?

我将相同的代码复制到 plunker 中,它工作得很好......可能出现哪些问题?

最佳答案

实际上错误是由 Google 的 api 脚本中的 initMap 生成的

 <script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>

基本上,当加载 Google Map API 时,就会执行 initMap 函数。如果没有 initMap 函数,则会生成 initMap is not a function 错误。

所以基本上你要做的是以下选项之一:

  1. 创建 initMap 函数
  2. 将回调函数替换为您自己的回调函数,该回调函数是出于相同目的而创建的,但命名为其他名称
  3. 如果您只想要一个空 function()(仅当您使用 Angular 时),请替换 &callback=angular.noop

关于angularjs - 类型错误 : window. initMap 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32496382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com