Hands On

HERE Fleet Telematics Custom Routes API

By Shruti Kuber | 29 November 2019

Logistics needs Last Mile services. For heavy goods, it is necessary that the delivery vehicle drops/ collects the goods from the unloading/loading docks to reduce manual effort, time and increase efficiency. Custom Routes can help guide delivery vehicles to the doors even in private locations.

Consider an example where a truck needs to deliver food for animals at Berlin's Tierpark. A regular routing service will route the truck to the main gate. From here, the truck has to either be escorted by an employee or an internal truck completes the last mile delivery. Instead, we can create a custom route through a back door which will allow the truck to directly deliver the fodder at the unloading dock. This saves a lot of time and inconvenience and achieves a much more efficient last mile delivery without disrupting regular activities.

Screen Shot 2019-11-29 at 11.42.56 AM

For creating a custom route, we need to upload a layer defining the route from the gate to the loading dock. This can be done by a simple GET request. The layer name always starts with "OVERLAY" and is the key to access this route. ONLY the app_id and app_code associated with this layer has access to this layer. Thus, only the delivery truck will be to see this route.


        GET http://cre.api.here.com/2/overlays/upload.json
        ?app_id={YOUR_APP_ID}
        &app_code={YOUR_APP_ID}
        &map_name=OVERLAYTIER
        &overlay_spec=[{
            "op":"create", 
            "shape":[[52.49464,13.52560],[52.49474,13.52594],[52.49487,13.52647],[52.49501,13.52701],[52.49514,13.52753],[52.49528,13.52806],[52.49541,13.52861],[52.49552,13.52906],[52.49563,13.52953],[52.49578,13.52999]],
            "layer":"LINK_ATTRIBUTE_FCN",
            "data":{"TRAVEL_DIRECTION":"B"}
            }]
        &storage=readonly
   

**If your browser does not support characters "[,],{,}", use their HEX codes "%5B,%5D,%7B,%7D," instead.

Screen Shot 2019-11-29 at 11.45.53 AM

Once the route is uploaded, you can now use the routing service to get the route with the additional parameter of the overlay name.


        let waypoint0 = '52.53086,13.38474',
        waypoint1 = '52.49578,13.52999',
        overlays = 'OVERLAYTIER',
        api = "cre.api.here.com/2/calculateroute.json?",
        mode = "fastest;truck;",
        app_id = "{YOUR_APP_ID}",
        app_code = "{YOUR_APP_CODE}",
        storage = "readonly",
        url = `http://${api}waypoint0=${waypoint0}&waypoint1=${waypoint1}&overlays=${overlays}&mode=${mode}&app_id=${app_id}&app_code=${app_code}&storage=${storage}`;

        fetch(url)
            .then(response => response.json())
            .then(response => {
                console.log(response);
                //draw polyline using shape in response
                }
            }, error => {
                console.log(error);
            });
    

The response will contain results similar to that of the response from a regular routing request. The shape objects for the route can be found under the individual legs. Screen Shot 2019-11-29 at 12.57.27 AM


        
    "response": {
        "metaInfo": {
            "overlays": "true"
        },
        "route": [
            {
                "mode": {
                    "type": "fastest",
                    "transportModes": [
                        "truck"
                    ],
                    "trafficMode": "disabled"
                },
                "boatFerry": false,
                "railFerry": false,
                "waypoint": [
                    {
                        "linkId": "+1199145808",
                        "mappedPosition": {
                            "latitude": 52.49828,
                            "longitude": 13.5232
                        },
                        "originalPosition": {
                            "latitude": 52.49828,
                            "longitude": 13.52321
                        },
                        "spot": 0.13684,
                        "sideOfStreet": "neither",
                        "seqNrOnRoute": 0,
                        "globalWayPointSeqNr": 0,
                        "type": "stopOver",
                        "mappedRoadName": "Am Tierpark"
                    },
                    {
                        "linkId": "+1",
                        "mappedPosition": {
                            "latitude": 52.49578,
                            "longitude": 13.52999
                        },
                        "originalPosition": {
                            "latitude": 52.49578,
                            "longitude": 13.52999
                        },
                        "spot": 1.0,
                        "sideOfStreet": "neither",
                        "seqNrOnRoute": 1,
                        "globalWayPointSeqNr": 1,
                        "type": "stopOver",
                        "mappedRoadName": "CustomLink-1"
                    }
                ],
                "leg": [
                    {
                        "length": 1698,
                        "travelTime": 250,
                        "link": [
                            {
                                "linkId": "1199145808",
                                "length": 50.0,
                                "remainDistance": 1698,
                                "remainTime": 250,
                                "shape": [
                                    52.49821,
                                    13.52324,
                                    52.49846,
                                    13.52308,
                                    52.4987,
                                    13.52293
                                ],
                                "functionalClass": 3
                            },...            
    

This method can also be used to block routes. Thus if you wish to prevent your fleet from using a certain bridge or certain road, you can block it using the block endpoint and mention the layer name while routing. Other use cases would include routing to private properties or internal roads within large properties.

Let me know in the comments how you use the custom routes API!