这里地图路由 API V8 - 多个 waypoints

Here Maps Routing API V8 - mutiple waypoints

我对 Here Maps Routing 非常陌生 API v8.

我试过这里提供的例子: https://developer.here.com/documentation/maps/3.1.15.1/dev_guide/topics/routing.html

我使用了如下所示的路由参数:

var routingParameters = {
  'routingMode': 'fast',
  'transportMode': 'car',
  'origin': '50.1120,8.6834',
  'destination': '52.5309,13.3846',
  'return': 'polyline'
};

现在我想在 routingParameters 中添加多个 waypoints,我尝试了以下相同的格式:

'via' : ['50.1234,8.7654', '51.2234,9.1123']

但是当我在routingParameters中使用上述行时,请求失败了。

您能否建议具有多个 waypoints 的请求的正确格式?

检查您使用的 HERE Maps JS API 的版本。从 3.1.19.0 版本开始支持。

因此计算具有多个 waypoints 的路线的方法是:

// departure point (origin)
var start = '52.550464,13.384223';

// collection of waypoints
var waypoints = [
  '52.529791,13.401389'
  '52.513079,13.424392'
  '52.487581,13.425079'
];

// end point (destination)
var end = '52.477545,13.447395'

// routing parameters
var routingParameters = {
  'origin': start,
  'destination': end,
  'via': new H.service.Url.MultiValueQueryParameter( waypoints ),

  'routingMode': 'fast',
  'transportMode': 'car',

  'return': 'polyline'
};

// Get an instance of the routing service version 8:
var router = platform.getRoutingService(null, 8);

// Call `calculateRoute` with the routing parameters,
// the success callback and an error callback function
// The implementation of the two callback functions is left out for brevity
// see documentation link below for callback examples
router.calculateRoute(routingParameters, onResultCallback, onErrorCallback)

使用 HERE Maps JS 计算路线 API:documentation

在 JS 中,添加多个 waypoints 的正确方法是使用 H.service.Url.MultiValueQueryParameter:

var routingParameters = {
  'routingMode': 'fast',
  'transportMode': 'car',
  'origin': '50.1120,8.6834',
  'via': new H.service.Url.MultiValueQueryParameter(['50.1234,8.7654', '51.2234,9.1123']);
  'destination': '52.5309,13.3846',
  'return': 'polyline'
};

有关详细信息,请查看 https://developer.here.com/documentation/maps/3.1.19.2/api_reference/H.service.Url.MultiValueQueryParameter.html

上的文档