A routing segment is a topology segment that represents a section of road or an otherwise linear, navigable stretch (see Segment).
The following will describe how to avoid routing segments with some examples.
Avoid segment of the returned route
If a route is calculated with the span=segmentRef specified, the returned route (blue line at Figure 1) would include a list of segment spans.
Figure 1. avoid segments
The following command can be used to calculate a list of segment spans between the given origin and destination:
curl-X GET \'https://router.hereapi.com/v8/routes?origin=45.484661,9.228382&destination=45.485542,9.234576&return=polyline&spans=segmentRef&transportMode=car&apikey={YOUR_API_KEY}'
The segment at offset 2 has segmentId and direction specified as $1:95058600#+, which converts to here:cm:segment:95058600#+ with the help of the refReplacement parameter. If this segment has to be avoided in both directions, then the route request should include avoid[segments]=here:cm:segment:95058600 without the direction part:
curl-X GET \'https://router.hereapi.com/v8/routes?origin=45.484785,9.229564&destination=45.485299,9.232146&avoid[segments]=here:cm:segment:95058600&return=polyline&spans=segmentRef&transportMode=car&departureTime=any&apikey={YOUR_API_KEY}'
And the returned route with avoidance (purple line at Figure 1) would go around the avoided segment.
Tip: Calculating a tiny route over one or few segments would allow to learn the ID of those segments and their direction when part of the route.
Avoid segment of the map in the specific direction
Assume a user would like to avoid traveling a certain road in a certain direction e.g. from east to west (see Figure 2).
Figure 2. avoid segment in direction of route
When fetching this segment from the map (see Segment) the user gets a segment ID as well as the geometry and the start and end nodes:
Positive direction of the segment corresponds to travelling from the start node to the end node. Since longitude of the start node is smaller than of the end node, then positive direction corresponds to travelling from west to east. To avoid traveling on this segment from east to west this segment should be avoided in the negative direction avoid[segments]=here:cm:segment:95058600#-:
curl-X GET \'https://router.hereapi.com/v8/routes?origin=45.485299,9.232146&destination=45.484785,9.229564&avoid[segments]=here:cm:segment:95058600#-&return=polyline&spans=segmentRef&transportMode=car&departureTime=any&apikey={YOUR_API_KEY}'