HERE地图JavaScript API多个路标

3
我使用Here Maps的Javascript API。我该如何以编程方式添加多个路标点?我尝试了以下代码:
  var via = new Array();
  var len = waypoints.length-1;
  for(var i = 1; i < waypoints.length-1; i++){
   via.push("waypoint" + i + ":" + waypoints[i][0] + "," + waypoints[i][1] + ",");
   //console.log(waypnts);
  }
  console.log(via);
   var router = platform.getRoutingService(),
routeRequestParams = {
  mode: 'fastest;truck;',
  grossWeight: '40',
  height: '4.0',
  width: '2.55',
  length: '18.25',
  axleCount: '5',
  excludecountries: 'CHE',
  representation: 'display',
  alternatives: '3',
  routeattributes : 'waypoints,summary,legs',
  maneuverattributes: 'direction,action',
  //RouteRepresentationModeType:'dragNDrop',
  start:waypoints[0][0] + "," + waypoints[0][1],

  destination:waypoints[len][0] + "," + waypoints[len][1]
};

我尝试通过routeRequestParams添加变量via,但没有成功。


你正在使用哪个版本的HERE Maps JS API? - Michael P. Bazos
这两个投票结果毫无可疑... - Liam
1个回答

6

要定义途经点,请使用H.service.Url.MultiValueQueryParameter类,该类在https://developer.here.com/documentation/maps/3.1.19.0/api_reference/H.service.Url.MultiValueQueryParameter.html中描述。请参考以下示例代码:

// Assumption: the platform is instantiated
let router = platform.getRoutingService(null, 8);
router.calculateRoute({
  'origin': '48.86,2.31',
  'destination': '48.86,2.35',
  // defines multiple waypoints
  'via': new H.service.Url.MultiValueQueryParameter(['48.8664,2.3234', '48.8703,2.3499']),
  // returns route shape as a polyline in response
  'return': 'polyline',
  'transportMode': 'car'
}, (result) => {
  const sections = result.routes[0].sections;
  const lineStrings = [];
  sections.forEach((section) => {
    // convert Flexible Polyline encoded string to geometry
    lineStrings.push(H.geo.LineString.fromFlexiblePolyline(section.polyline));
  });
  const multiLineString = new H.geo.MultiLineString(lineStrings);
  const bounds = multiLineString.getBoundingBox();
  // render route on the map
  map.addObject(new H.map.Polyline(multiLineString, {style: {lineWidth: 5}}));
  // zoom to polyline
  map.getViewModel().setLookAtData({bounds});
}, console.error);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接