ReferenceError:未定义谷歌

Bon*_*Kun 12 google-maps

我在我的网站上使用google map的api来显示几个位置.谷歌地图在我的本地解决方案中工作得很好,但在我的网站上却没有.我改变了这个来源

<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.5&sensor=false"> </script>
Run Code Online (Sandbox Code Playgroud)

对这一个.我再次改变了这个

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
Run Code Online (Sandbox Code Playgroud)

有这个...

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"> </script>
Run Code Online (Sandbox Code Playgroud)

只有它说:ReferenceError:谷歌没有定义

有谁熟悉这样的问题?

Bon*_*Kun 27

由于我的网站使用https进行连接,因此我无法使用http://maps.google.com/maps/api/js?sensor=false.当我调试整个页面时,此链接显示:警告:页面index.html运行不安全的内容.所以我在google上进行了另一次搜索并遇到了这个问题.所以基本上导致问题的是不在源部分使用https链接,所以正确的链接将是(对我而言)

https://maps.google.com/maps/api/js?sensor=false
Run Code Online (Sandbox Code Playgroud)

现在everythnig工作得很好!

  • @ParthChavda,请尝试使用//maps.google.com/maps/api/js?sensor=false (2认同)

Mar*_*elo 14

这是一个旧网址.如果您查看文档中的示例,几乎所有示例都使用:

 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
Run Code Online (Sandbox Code Playgroud)


小智 8

对我来说,使用新的 Google Maps API,这个解决方案很有效:只需从 goolge 提供的脚本中省略“async defer”即可:

<script async defer src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>
Run Code Online (Sandbox Code Playgroud)

<script src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>
Run Code Online (Sandbox Code Playgroud)