【问题标题】:HERE heatmap uses url parameters but url is +7.000 chars and returns status 400 Bad RequestHERE 热图使用 url 参数,但 url 为 +7.000 字符并返回状态 400 Bad Request
【发布时间】:2022-01-13 12:10:18
【问题描述】:

我正在使用HERE 进行地理编码和生成热图。

热图使用 URL 参数,但是当有许多数据点时,URL 可能超过 7.000 个字符,这远远超过了浏览器限制 2.048,然后引发 400 错误。 当数据点较少时,热图可以正常工作。

我将 URL 发送到前端并在浏览器中呈现返回的图像。

除了 URL 参数之外,我还有什么方法可以使用吗?还是直接从服务器调用 HERE 端点,将实际图像返回给前端?或任何其他“解决”此问题的解决方案?
我宁愿不必更改地图提供者!

我正在使用 NestJS 和 Angular 最新版本。

URL 示例(足够短,可以正常工作) https://image.maps.ls.hereapi.com/mia/1.6/heat?apiKey=xxxxxxxxxxx&noblur=&w=2048&h=1024&a0=55.6059,12.99563&l0=2&rad0=1000&a1=55.61218,12.97896&l1=2&rad1=1000

谢谢

编辑:我暂时解决了这个问题

if (this.heatUrl.length < 2000) {
  this.heatUrl += (this.getParams(i, partLoc[i].coordinates, partLoc[i].weight));
};

这会减少约 150 个数据点的约 100 个数据点,但由于它们是按时间顺序排序的,因此仅占元素的 10-15%。
仍在寻找合适的解决方案。

【问题讨论】:

  • 要在 HTTP 请求中传输大量参数,您应该使用 POST 方法而不是 GET。如果我是你,我会先询问 HERE tech.support 团队他们的 API 是否支持 POST 请求
  • 谢谢,但 HERE 不支持热图上的 POST 请求
  • @HEREDeveloperSupport 我不明白你的编辑???实际上,我本来希望您能给出答案,但您只需添加标签geocoding,具有讽刺意味的是,这不是这个问题的意义所在!

标签: heatmap geocoding here-api


【解决方案1】:

关于https://developer.here.com/documentation/map-image/dev_guide/topics/request-format.html 上的文档-“注意:除了路由资源,不支持 POST 方法,并且它仅限于最大 8K 的有效负载。”

在这种情况下,您只需使用带有热图的 JS API 即可实现您的目标,使用以下代码:

// Create a provider for a semi-transparent heat map:
  var heatmapProvider = new H.data.heatmap.Provider({
    colors: new H.data.heatmap.Colors({
      '0': 'blue',
      '0.5': 'red',
      '1': 'yellow'
    }, true),
    opacity: 0.7,
    // Paint assumed values in regions where no data is available
    assumeValues: false
  });

  // Add the data:
  heatmapProvider.addData([
    {lat: 52, lng: 13, value: 3},
    {lat: 52, lng: 13.5, value: 1},
    {lat: 52, lng: 14, value: 3}
  ]);


  // Add a layer for the heatmap provider to the map:
  map.addLayer(new H.map.layer.TileLayer(heatmapProvider));

上面的 JS Fiddle 示例:https://jsfiddle.net/po5r0w3b/1/
文档:https://developer.here.com/documentation/maps/3.1.30.7/api_reference/H.data.heatmap.Provider.html

其他例子:

【讨论】:

    猜你喜欢
    • 2017-09-02
    • 2019-02-24
    • 2016-12-31
    • 2016-03-16
    • 2012-04-21
    • 1970-01-01
    • 2017-10-28
    • 2020-11-01
    相关资源
    最近更新 更多