Hands On
100DaysOfCode

Solutions: Day 66-70 #100DaysOfCode

By Shruti Kuber | 12 June 2020

Try HERE Maps

Create a free API key to build location-aware apps and services.

Welcome to week 14 #100DaysOfCode with HERE. With this week, we are kicking off with truck routing and will take a look at routing features specific to logistics with Routing v7.
If you have no idea what I'm talking about, take a look at this blog post which will tell you everything about #100DaysOfCode. If you have missed the solutions for days 0-65, you can read them in the previous blogs posts or on our YouTube channel.
Let's begin!

Day 66/100

Day 66 is pretty straightforward as we just need to change the routing mode. We have already seen that the Routing v7 API has several transport modes, one of them being a truck. Moreover, the API lets us control the restriction penalty associated with truck routing. What does this mean you say? Well, if you were to find a route for a car and a truck between the same two points, the route will often vary. This is due to the fact that different kinds of roads all over the world have different restrictions on the kind of vehicle that can be driven on them. In some places, trucks aren't allowed in the city centers at all. While in others, they are allowed only at night or after peak evening hours. Whatever the restrictions might be, they are considered when you get a route for a truck. Although you can adjust how strictly you want to follow that while getting a route. All you need to to is set the truckRestrictionPenalty to soft or strict


var routingParameters = {
waypoint0:"52.53086235,13.38475371",
waypoint1:"52.1370754,11.6326044",
mode:"fastest;truck;traffic:enabled",
truckRestrictionPenalty:'strict',
alternatives:3,
representation: "display",
};


Day 67/100

While we talked about restrictions on trucks simply by the virtue of being trucks, restrictions also exist depending on what they carry. For day 67, we are looking at a truck which carries radioactive material. How do you tell this to a routing engine. As I mentioned before, we are going to concentrate on logistics related routing here and so we have this covered. The parameter shippedHazardousGoods lets you mention a few types of goods that trucks may carry which can affect the route assigned to them. Feel free to check out the different Hazardous Good Types.


var routingParameters = {
waypoint0:"52.53086235,13.38475371",
waypoint1:"52.1370754,11.6326044",
mode:"fastest;truck;traffic:enabled",
truckRestrictionPenalty:'strict',
alternatives:3,
representation: "display",
};


Day 68/100

Another thing you need to consider while driving a truck is the height of the truck. You need to make sure the route you've taken does not have tunnels, bridges or any other construction that may not allow your truck to easily pass through it. Roads have signs on them to indicate that, but you don't want to know about a restriction only when you reach there. To be prepared, we can create a Truck Profile and get a route accordingly. One of the most basic parameters of the truck profile is the height which can be specified in meters.


var routingParameters = {
waypoint0:"52.518543744,13.37906420",
waypoint1:"52.14837255,11.617700516",
mode:"fastest;truck;traffic:enabled",
truckRestrictionPenalty:'strict',
height:3,
alternatives:3,
representation: "display",
};


Day 69/100

After specifying the height, you naturally would want to specify the length of the truck. This often includes specifying the number of trailers attached to the main body of the truck. For this we are going to use parameters trailersCount, axleCount and length. And like height, length is also specified in meters.


var routingParameters = {
waypoint0:"52.53086235,13.38475371",
waypoint1:"52.1370754,11.6326044",
mode:"fastest;truck;traffic:enabled",
truckRestrictionPenalty:'strict',
trailersCount:1,
axleCount:4,
length:20,
alternatives:3,
representation: "display",
};


Day 70/100

.And finally for smaller roads, bridges, mountain roads, it is important to know the weight limit. Roads also have a limit of load per axle that a truck can carry. These are again parameters within the truck profile that you can easily set with limitedWeight and weightPerAxle where both the weights are specified in tonnes.


var routingParameters = {
waypoint0:"52.53086235,13.38475371",
waypoint1:"52.1370754,11.6326044",
mode:"fastest;truck;traffic:enabled",
truckRestrictionPenalty:'strict',
trailersCount:1,
axleCount:4,
length:20,
limitedWeight:40,
weightPerAxle:10,
alternatives:3,
representation: "display",
};


That was week 14 of #100DaysOfCode With HERE. We are going to continue with routing for logistics in the coming weeks so keep watching this space. Keep following us on Twitter for more tasks and complete all 100 days. If you want to watch the video version of these solutions, take a look at our playlist for #100DaysOfCode on YouTube. If you want the code snippets of the APIs covered with #100DaysOfCode, head over to the 100daysofcode GitHub repository.
Meanwhile, read this blog post to know more about what a success #HackForBetterDays was. While you're at it, check out how to use HERE APIs easily with POSTMAN.
Happy coding!