【问题标题】:How to call HERE Maps API v3 using HTTPS如何使用 HTTPS 调用 HERE Maps API v3
【发布时间】:2015-02-17 20:01:53
【问题描述】:

如何通过 HTTPS 调用 HERE 地图?

我在我的服务器上使用 HTTPS,所以当我调用它时:

    <script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
    <script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>

由于“混合内容”,浏览器阻止了请求,因此没有显示地图...

我尝试将脚本源中的“http”更改为“https”,但我遇到了同样的问题,因为两个 javascript 在其代码中都有“http”调用。

后端是用 Grails 编写的,通道是使用 Spring Security Core 插件保护的。

【问题讨论】:

    标签: javascript grails here-api


    【解决方案1】:

    你需要从 https 加载 API,另外你需要设置:

    // Create a platform object to communicate with the HERE REST APIs
    var platform = new H.service.Platform({
        useCIT: true,
        app_id: app_id,
        app_code: app_code,
        useHTTPS: true
    });
    

    诀窍是 useHTTPS: true,如文档中所述:HERE Developers Guide

    【讨论】:

      【解决方案2】:

      对于 HTTPS:

      • 通过“https协议”加载js和css文件
      • 在创建 H.service.Platform 实例时强制使用 HTTPS

      对于“https 协议”,在 head 部分加载 CSS:

      <link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" />
      

      对于“https协议”,在关闭BODY标签之前加载JS:

      <script src="https://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
      <script src="https://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
      <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
      <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
      

      通过这些步骤,所有 js 和 CSS 都已正确加载。但是当 SDK 加载 Tiles 时,您可能会遇到一些问题。要允许 SDK 正确加载 HTTPS 协议所需的所有资产,您需要在 Platform 构造函数中使用“useHTTPS”选项:

      this.platform = new H.service.Platform({
        'app_id': process.env.VUE_APP_HERE_APP_ID,
        'app_code': process.env.VUE_APP_HERE_APP_CODE,
        'useHTTPS': true
      })
      

      更新:对于 3.1,我对 HTTPS 协议没有任何问题。

      【讨论】:

      • 相关协议现在被视为anti-pattern,如果支持,您应该始终使用https
      猜你喜欢
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多