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

HERE Maps API路由与Toll Cost服务同参数返回不同路线问题求助

Fixing Route vs Toll Cost Service Discrepancy with HERE Maps API

It looks like you're hitting a common gotcha with HERE Maps API: even when using identical parameters, the Route Service and Toll Cost Service can return different routes because their underlying calculation logics are optimized for distinct goals. Here's how to align them to meet your requirement of prioritizing toll-free routes, only falling back to toll roads when no alternatives exist:

1. Understand the Parameter Conflict

Your current setup uses cost_optimize=1 alongside tollroad:-2, but these two parameters can clash:

  • cost_optimize=1 in the Route Service optimizes for overall trip cost (combining fuel, time, and tolls), which might prioritize a shorter toll road if it reduces total trip cost—even if you want to avoid tolls.
  • tollroad:-2 tells the service to avoid toll roads unless no alternative exists, but the cost optimization logic can override this priority.

The Toll Cost Service, by contrast, focuses specifically on toll-related costs, so it’s more likely to surface toll road routes when they’re the most cost-efficient from a toll-only perspective.

2. Adjust Route Service Parameters to Prioritize Toll Avoidance

Modify your Route Service request to explicitly prioritize toll avoidance over general cost optimization:

Updated Route Request URL

https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apikey=&cost_optimize=0&tollVehicleType=3&vehicleNumberAxles=3&trailerNumberAxles=2&waypoint0=39.72793,-105.01245&waypoint1=41.09575,-104.84611&routeAttributes=sm,t&mode=fastest;truck;traffic:disabled;tollroad:-2

Key changes:

  • Set cost_optimize=0 to disable general cost optimization, ensuring tollroad:-2 takes top priority.
  • Add t to routeAttributes to include detailed toll information in the response—this lets you verify if any segments of the route use toll roads, even if the summary flags don’t list "tollroad" (summary flags only highlight major route features).

3. Verify Toll Road Strictness

If the above adjustment still returns a route without toll roads but the Toll Cost Service shows a toll route, test with tollroad:-3 (strictly avoid toll roads):

  • If this returns a "no route found" error, that confirms there are no fully toll-free routes between your waypoints. Your original tollroad:-2 route is the only feasible option, and the summary flags might not be reflecting minor toll segments correctly.
  • If it returns a valid route, then your original tollroad:-2 request wasn’t working as expected, and setting cost_optimize=0 should fix the discrepancy.

4. Align Toll Cost Service Parameters

To ensure consistency across both services, update your Toll Cost Service request to match the adjusted Route Service parameters (set cost_optimize=0):

Updated Toll Cost Request URL

https://tce.api.here.com/2/calculateroute.json?app_id=&app_code=&cost_optimize=0&mode=fastest;truck;traffic:disabled;tollroad:-2&currency=USD&tollVehicleType=3&vehicleNumberAxles=3&trailerNumberAxles=2&representation=overview&waypoint0=39.72793,-105.01245&waypoint1=41.09575,-104.84611&routeAttributes=sm

5. Reach Out to HERE Support

If you still see discrepancies after aligning parameters, the issue might stem from differences in route databases or calculation engines between the two services. Submit a support ticket with your full request/response details, and HERE’s team can investigate the underlying logic mismatch.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 00:17:37