HERE Technologies LogoHERE
HERE Technologies LogoHERE
HERE Technologies LogoHERE
APIs

3 min read

12 January 2023

HERE Routing API supports polygons for avoid areas

here routing polygon avoid area

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.

Sample Application

Request Parameters

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);

Polygon Formats

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:13.082,52.416;13.628,52.626;13.482,52.916 - Polygon in Berlin

polygon:{encoded_polyline} - encoded Flexible Polyline

* Maximal count of polygons is 20. Count of bounding boxes + polygons <= 250 * Minimal count of coordinates in one polygon is 3. If less - corresponding error will be returned. * Maximal count of coordinates in one polygon is 16. If more - corresponding error will be returned. * The polygon is closed automatically, there is no need to duplicate the first point as the last one. * Self-intersecting polygons are not supported. If they are present in the request, the corresponding error will be returned.

polygon:BF05xgKuy2xCx9B7vUl0OhnR54EqSzpEl-HxjD3pBiGnyGi2CvwFsgD3nD4vB6e

Resources

For more information regarding HERE Routing API and its avoidance feature, see the following resources:

Portrait of Erwin Soekianto

Erwin Soekianto

Developer Evangelist

Share article

Sign up for our newsletter

Why sign up:

  • Latest offers and discounts

  • Tailored content delivered weekly

  • Exclusive events

  • One click to unsubscribe