You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过HERE API获取各途经点之间的距离?

Getting Segment Distances Between Waypoints with HERE Route API

Hey there! Let's break down how to grab the exact distances for your two route segments (waypoint0 → waypoint1 and waypoint1 → waypoint2) using the HERE Route API.

Your current request is already close — you've included sm (summary data) in routeAttributes, which is key. The main tweak you need is to adjust the legAttributes parameter to get per-segment details instead of just total route info.

Updated Request

Change legAttributes=none to legAttributes=li,sm (this enables leg information and leg-specific summaries). Here's your modified request string:

https://tce.cit.api.here.com/2/calculateroute.json?mode=fastest;truck;traffic:disabled&truckType=tractorTruck&maneuverAttributes=none&combineChange=true&routeAttributes=none,wp,sm,sh,no&linkAttributes=none&legAttributes=li,sm&detail=1&alternatives=2&rollup=total,country&jsonattributes=41&waypoint0=geo!stopOver!53.55155000,9.99960000&waypoint1=geo!passThrough!45.97279231,4.73305852&waypoint2=geo!stopOver!41.15305000,-8.57573000

What This Changes

  • With legAttributes=li,sm, the API will return a legs array in the JSON response. Each entry in this array corresponds to one segment between your waypoints.
  • Inside each leg object, you'll find a summary field that includes the distance (in meters by default) for that specific segment, along with travel time and other relevant metrics.

Example Response Snippet

Here's a simplified look at what you'll get for the legs section:

"legs": [
  {
    "summary": {
      "distance": 895678,
      "travelTime": 37260
      // Additional summary details will appear here
    }
  },
  {
    "summary": {
      "distance": 789123,
      "travelTime": 32100
      // Additional summary details will appear here
    }
  }
]

The first leg's distance is for waypoint0 → waypoint1, and the second is for waypoint1 → waypoint2.

A quick note: since waypoint1 is marked as passThrough, the API still recognizes it as a split point for legs when you enable legAttributes=li,sm, so you'll get the exact segment distances you need.

Hope this solves your problem — let me know if you need further clarification! 😊

内容的提问来源于stack exchange,提问作者cslehel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:32:38