使用HERE API强制指定跨境路线的边境过境点
Great question! Yes, the HERE API absolutely lets you lock in a specific border crossing for your cross-border routes—your current issue with multiple border hops and the detour through Laredo happens because without explicit constraints, the API’s default routing logic picks what it calculates as the "optimal" route (based on factors like travel time, distance, or estimated border wait times) instead of your preferred path through Tijuana.
Here’s how to get the route you want:
1. Force the Route Through Your Preferred Border Crossing with Waypoints
The most reliable method is to add your desired Tijuana border crossing as a mandatory waypoint in your route request. This tells the API to strictly plan a path that goes through that exact point, eliminating detours through other crossings like Laredo.
Step-by-Step Implementation
- First, grab the precise coordinates of your target Tijuana border crossing (for example, the main San Ysidro Port of Entry is at
32.5403,-117.0324—adjust this if you need a different port). - Structure your API request to include three points in order: your origin (Monterrey), the Tijuana border waypoint, and your destination (Los Angeles).
Example API Request
GET https://router.hereapi.com/v8/routes ?apikey=YOUR_API_KEY &transportMode=car &origin=25.6751,-100.3185 // Coordinates for Monterrey, MX &destination=34.0522,-118.2437 // Coordinates for Los Angeles, CA &via=32.5403,-117.0324 // Coordinates for Tijuana-San Ysidro border crossing &return=polyline,summary
2. Tweak Parameters to Avoid Unwanted Border Crossings
If you still see unexpected border hops after adding the waypoint, try these extra adjustments:
- Ensure your waypoint coordinate is as close as possible to the actual border crossing (not just the city center of Tijuana) to leave less room for the API to reroute.
- You can also set
routePurpose=shortestto prioritize distance over estimated travel time, which can help eliminate unnecessary detours that might trigger extra border crossings.
Why You Saw Multiple Border Crossings Initially
The HERE API’s default routing algorithm balances several factors—like expected border wait times, road speed limits, and overall travel time. In your case, it likely picked the Laredo crossing because it calculated a faster total trip time (even with the longer drive) or had lower estimated wait times. The back-and-forth between San Diego and Tijuana happened because the API was trying to adjust the route without a clear mandatory waypoint, leading to unintended border hops.
内容的提问来源于stack exchange,提问作者BurmajaM

