ReferenceError:未定义谷歌

时间:2012-09-03 13:47:55

标签: google-maps

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

<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.5&sensor=false"> </script>

到这一个。我又改变了这个

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

这一个......

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

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

有没有人熟悉这样的问题?

4 个答案:

答案 0 :(得分:23)

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

https://maps.google.com/maps/api/js?sensor=false

现在everythnig工作正常!

答案 1 :(得分:14)

这是一个旧网址。如果您查看examples from the documentation,几乎所有人都会使用:

 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 

答案 2 :(得分:1)

我在rails应用程序中遇到了这个问题。

googlemap的请求来自http和https网页

它解决了:

= javascript_include_tag "//maps.google.com/maps/api/js?sensor=false"

如果协议未定义rails insert inserted

答案 3 :(得分:1)

对我来说,使用新的Google Maps API,此解决方案就可以了: 只需从goolge提供的脚本中省略“异步延迟”即可:

<script async defer src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>

TO

<script src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>
相关问题