Kyle S
Kyle S

Reputation: 448

Error when calculating route in nokia / ovi / here maps

This one's been driving me crazy for hours. Nokia maps javascript api is erroring out on me if a routing request fails for any reason. While testing I have it trying to give me a driving route from the middle of the ocean to some random other coordinates I put in. I've looked into the nokia code as much as I've been able to.

So, obviously, trying to make the route fails and this is the code coming back

(function(){nokia.maps.net.Request.callbacks[10](11,arguments);})({"details":"NOROUTE: Request failed","additionalData":[],"type":"ApplicationError","subtype":"NoRouteFound"})

That's what gets sent to what I assume is some error handling code in routing-nlp.js

qb:function(a){
    var b=a.details;a.additionalData&&(b+=" Key: "+a.additionalData[0].key+", Value: "+a.additionalData[0].value);
    return{type:a.type.charAt(0).toLowerCase()+a.type.substr(1),subtype:a.subtype.charAt(0).toLowerCase()+a.subtype.substr(1),message:b}}});

May have got the wrong number of brackets in the copy paste there, but everything else is as it is shown. As you can see, the returned information just has an empty array for the additionalData so it shouldn't be trying to extract anything from it...but it does. And then errors because there is nothing at a.additionalData[0].key (cannot read property 'key' of undefined).

This is all kicked off by:

        var router = new nokia.maps.routing.Manager();

        router.addObserver("state", onRouteCalculated);

        var waypoints = new nokia.maps.routing.WaypointParameterList();
        waypoints.addCoordinate(new nokia.maps.geo.Coordinate(20, 54));
        waypoints.addCoordinate(new nokia.maps.geo.Coordinate(0.06275, 0.3966));

        var modes = [{
            type: "shortest",
            transportModes: ["car"]
        }];

        router.calculateRoute(waypoints, modes);

Using js api from https://js.api.here.com/ee/2.5.3/jsl.js?with=all

EDIT: Answer is that this is currently because of a bug in the response from Enterprise Routing. See comments on the answer below.

Upvotes: 0

Views: 946

Answers (1)

Jason Fox
Jason Fox

Reputation: 5290

The reason you are getting an error is because your start point is in the middle of the Empty Quarter of Saudi Arabia, where there are literally no roads for miles around. The routing api tries but fails to find a nearby road to start the route from an sends back an error response.

The JavaScript API is simply a wrapper around the underlying RESTful Routing API. If you look at the underlying response you will get the following error:

{
    "type":"ApplicationError",
    "subtype":"NoRouteFound",
    "details":"Error is NGEO_ERROR_ROUTE_NO_START_POINT",
    "additionalData":[
        {
            "key":"error_code",
            "value":"NGEO_ERROR_ROUTE_NO_START_POINT"
        }
    ],
    "metaInfo":
    {
        "timestamp":"2013-12-16T11:14:22.991",
        "mapVersion":"8.30.52.113",
        "moduleVersion":"7.2.39.0_CD-793_1",
        "interfaceVersion":"2.4.37"
    }
}

This is handled in the JavaScript Wrapper by setting the state of the Routing Manager to "failed"

Presumably you already have an observer for the state attribute in your code, you can extend it to handle the error case as shown:

onRouteCalculated = function (observedRouter, key, value) {
        if (value == "finished") {
            var routes = observedRouter.getRoutes();
            var mapRoute = new 
                    nokia.maps.routing.component.RouteResultSet(routes[0]).container;
            map.objects.add(mapRoute);
            map.zoomTo(mapRoute.getBoundingBox(), false, "default");
        } else if (value == "failed") {
            alert("The routing request failed.");
        }
    };

The code for a fully working example with error handling can be found within the API Explorer

Upvotes: 1

Related Questions