14

我在我的网站中使用谷歌地图的 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: google is not defined

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

4

4 回答 4

31

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

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

现在一切正常!

于 2012-09-05T15:35:12.450 回答
14

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

 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
于 2012-09-03T18:50:47.630 回答
4

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

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

<script src="https://maps.googleapis.com/maps/api/js?key={your_key}"></script>
于 2019-01-08T10:38:12.200 回答
1

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

对 googlemap 的请求来自 http 和 https 页面

它解决了:

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

如果协议未定义 rails 自动插入

于 2013-12-17T08:24:48.630 回答