HERE Routing API supports polygons for avoid areas
Last month, we released a lot of exciting new features to HERE platform, including updates to Location Services APIs and SDKs, Routing API, Isoline Routing API, Waypoints Sequencing API, and more. For complete information, see December 2022 platform release notes. In this blog, we will discuss the update to HERE Routing API, which now supports polygons for avoid areas.
HERE Routing API can avoid routes that violate certain features of the road networks or that go through user-specified geographical bounding boxes. One such example is requesting a route to an island that is only reachable with ferries by specifying avoid[features]=ferry
parameter in the request. In addition to the option to provide specific road segments or bounding boxes that should be avoided for a route calculation, you can now also specify up to 20 polygons in a routing request. This allows a more precise and simple way to define areas that should be avoided. See a sample application below showing the fastest car route from the Port of Long Beach to Fontana with avoid polygon area and displaying it on the map. By default, the route uses the red polygon area as avoid area, but you can choose to show the route with the green polygon or without any avoid area by clicking on the three buttons on top of the map. This sample is built using HERE Maps API for Javascript and modified from the Map with Driving Route from A to B sample.
To specify polygons for avoid areas we need to use the parameter avoid[areas]=polygon:xxx...
. Below are the sample request parameters used in the sample above. For the two polygons that are used in this sample, we had the coordinates of the vertices that are relevant to the possible detours of the route then created and added the polygons to the map inspired by Polygon on the Map sample.
var routeRequestParamsWithAvoid = {
'routingMode': 'fast',
'transportMode': 'car',
'origin': '33.751305,-118.188812', // Port of Long Beach
'destination': '34.092232,-117.435051', // Fontana
'avoid[areas]': 'polygon:34.073334,-118.027496;33.888504,-117.813255;33.895847,-118.220070';, //red polygon
'return': 'polyline,turnByTurnActions,actions,instructions,travelSummary'
};
function calculateRouteFromAtoB(platform, params) {
var router = platform.getRoutingService(null, 8);
router.calculateRoute(
params,
onSuccess,
onError
);
}
calculateRouteFromAtoB(platform, routeRequestParamsWithAvoid);
The parameter avoid[areas]
is a pipe-separated list of user-defined areas that routes will avoid going through. The list is limited to 250 items. Format: {shape1}|{shape2}|{shape3}...
. It supports two shape formats: bounding box(avoid[areas]=bbox:xxx...
) and polygon (avoid[areas]=polygon:xxx...
). The polygon can be a polygon on earth that defines an area to avoid following these possible formats:
Format | Notes | Example |
polygon:{lat},{lon};{lat},{lon};{lat},{lon}... |
Support only 2D polyline (without elevation specified). |
|
polygon:{encoded_polyline} - encoded Flexible Polyline |
|
polygon:BF05xgKuy2xCx9B7vUl0OhnR54EqSzpEl-HxjD3pBiGnyGi2CvwFsgD3nD4vB6e |
For more information regarding HERE Routing API and its avoidance feature, see the following resources:
- HERE Maps API for Javascript
- Map with Driving Route from A to B sample
- Polygon on the Map sample
- HERE Routing API Reference (click on the
avoid
parameter to see more details) - Avoidance Tutorial
- Avoid Routing Zones Tutorial
- Avoid Area Tutorial
- Avoid Routing Segments Tutorial
- Exclude Countries Tutorial
Have your say
Sign up for our newsletter
Why sign up:
- Latest offers and discounts
- Tailored content delivered weekly
- Exclusive events
- One click to unsubscribe