Google地图无法在https://中工作 [英] Google maps not working in https://

查看:819
本文介绍了Google地图无法在https://中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在http上使用google地图,它工作得很好。但是,当我安装SSL相同的证书,它停止工作。它给我错误


混合内容: https:// url '是通过HTTPS加载的,但
请求的是不安全的脚本
' http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js?_=1 ***************。
此请求已被阻止;内容必须通过HTTPS提供。



更新: 2016 Google已停用此库的 google-maps-utility-library-v3.googlecode.com 源代码。但是,自Google将源代码移至GitHub后,一会儿回来,请考虑本帖末尾介绍的GitHub详细信息,特别是关于将脚本和资源直接包含在您的项目中的最终说明

除了将您的脚本包含网址从以下位置更改:

  http:// google-maps-utility -library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js 

到:

  https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src / markerclusterer.js 

当您沿着以下方式实例化MarkerClusterer时,还需要指定imagePath选项行:

  var mc =新的MarkerClusterer(地图,标记,{
imagePath:'https:// googl e-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m'
});

这样可以避免以下警告,它与您突出显示的脚本错误具有相同的含义: / p>


混合内容: https://网址'已通过HTTPS加载,但请求的图像不安全' http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m1.png '。此内容还应通过HTTPS提供。


发生这种情况的原因是,默认情况下,MarkerClusterer库使用以下非https设置为群集映像的根目录(m1.png,m2.png等):

  MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_ = 
'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/'+
'images / m'

虽然我们之前遇到过这个问题,但它似乎已经被解决以响应库的GitHub存储库上的以下请求:



将HTTP更改为HTTPS图片链接



GitHub版本可以从 RawGit ,使用以下脚本网址:

  https://cdn.rawgit.com/googlemaps /js-marker-clusterer/gh-pages/src/markerclusterer.js 

以及下面的imagePath可以用于访问GitHub图像:

  var mc =新的MarkerClusterer(地图,标记,{
imagePath:' https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m'
});

虽然上述网址(包含cdn前缀)有没有流量限制或限制,并且文件通过超快全球CDN提供,请记住 RawGit是一项免费托管服务,不提供正常运行时间或支持担保

以下是所有答案的详细介绍:

链接并执行托管在GitHub上的外部JavaScript文件



如果您链接到GitHub上的文件,在生产中您应该考虑定位特定的发布标签,以确保您获得了期望的脚本发行版本。

然而,作为保管人o如果js-marker-clusterer版本库尚未创建任何版本,则目前尚不可能。

因此,您应该认真考虑下载并将图书馆及其资源直接纳入您项目的生产用途。


I am using google maps on http, it is working perfectly fine. But when i installed ssl certificates over the same, it stopped working. It is giving me errors

Mixed Content: The page at 'https://url' was loaded over HTTPS, but requested an insecure script 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js?_=1***************'. This request has been blocked; the content must be served over HTTPS.

解决方案

UPDATE: On May the 12th 2016 Google decommissioned the google-maps-utility-library-v3.googlecode.com source for this library. However, since Google moved the source over to GitHub a while back, please consider the GitHub details covered at the end of this post and, in particular, the final note regarding including the script and resources directly in your project

In addition to changing your script inclusion url from:

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js

to:

https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js

you'll also need to specify the imagePath option when instantiating your MarkerClusterer along the following lines:

var mc = new MarkerClusterer(map, markers, { 
    imagePath: 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m' 
});

This will avoid the following warning which covers the same ground as the script error you've highlighted:

Mixed Content: The page at 'https://url' was loaded over HTTPS, but requested an insecure image 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m1.png'. This content should also be served over HTTPS.

The reason this occurs is that, by default, the MarkerClusterer library uses the following non https setting as the root for its cluster images (m1.png, m2.png etc.):

MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_ =
    'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/' +
    'images/m'

Whilst we encountered this issue a while back, it does appear to have been addressed in response to the following pull request on the library's GitHub repository:

Changed HTTP to HTTPS in image link

This GitHub version can be accessed from RawGit by using the following script url:

https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/src/markerclusterer.js

and the following imagePath can be used to access the GitHub images:

var mc = new MarkerClusterer(map, markers, { 
    imagePath: 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m' 
});

Whilst the above urls (with the cdn prefixes) have no traffic limits or throttling and the files are served via a super fast global CDN, please bear in mind that RawGit is a free hosting service and offers no uptime or support guarantees.

This is covered in more detail in the following SO answer:

Link and execute external JavaScript file hosted on GitHub

This post also covers that, if you're linking to files on GitHub, in production you should consider targeting a specific release tag to ensure you're getting the desired release version of the script.

However, as the custodians of the js-marker-clusterer repository have yet to create any releases, this isn't currently possible.

As a result, you should seriously consider downloading and including the library and its resources directly in your project for production purposes.

这篇关于Google地图无法在https://中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆