【问题标题】:How to avoid mixed content warnings with Google Maps Marker Clusterer Plus如何使用 Google Maps Marker Clusterer Plus 避免混合内容警告
【发布时间】:2015-05-07 12:44:39
【问题描述】:

当您的网站通过 HTTPS 加载时,Google Maps Marker Clusterer Plus 默认图标仍通过纯 HTTP 加载

这会触发大多数浏览器的“混合内容”警告

【问题讨论】:

    标签: google-maps https google-maps-markers markerclusterer


    【解决方案1】:

    您也可以通过在实例化 MarkerClusterer 时指定 imagePath 选项(如下所示)以与 Anthony's answer 类似的方式解决此问题:

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

    更新: 不久前Google moved the MarkerClustererPlus source over to GitHub,并且 Google 代码版本现已停产,您应该使用以下脚本 URL 之一来使用新的 GitHub 托管版本(标准和打包版本):

    https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/src/markerclusterer.js
    https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/src/markerclusterer_packed.js
    

    在实例化 MarkerClusterer 时,您还需要将 imagePath 选项指向新的托管位置,如下所示:

    var mc = new MarkerClusterer(map, markers, { 
        imagePath: 'https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m' 
    });
    

    在生产中,应使用上述 url(带有 cdn 前缀),因为它们有 no traffic limits or throttling and the files are served via a super fast global CDN。但是请记住,作为一项免费服务,它提供no uptime or support guarantees

    以下 SO 答案更详细地介绍了访问从 Git 托管的文件:

    Link and execute external JavaScript file hosted on GitHub

    【讨论】:

    • 感谢您的回答和更新 - 代码不应该再依赖于谷歌代码,因为它是日落前一段时间
    • 我完全同意,尽管似乎有不少开发人员已经被这个问题所困扰 - 主要是因为谷歌地图实用程序库提供的示例仅引用(并且仍然引用)谷歌代码版本
    【解决方案2】:

    只需添加这一行:

    MarkerClusterer.IMAGE_PATH = "https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/images/m";
    

    在调用您的 Google Maps Marker Clusterer Plus 之前:

    var markerCluster = new MarkerClusterer(map, allMarkersArray, mcOptions);
    

    【讨论】:

    • 以防万一它有用,我已经更新了我的答案,包括 Google 停用 MarkerClustererPlus 脚本的 Google 代码副本的详细信息
    猜你喜欢
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 2013-01-25
    • 2012-01-29
    • 2015-07-25
    • 1970-01-01
    相关资源
    最近更新 更多