Post Route Directions - Empty Route returned

Andrew Martin 20 Reputation points

I'm getting an empty Feature response back for a specific route. Waypoints are as follows:

[53.96119, -1.09768], [54.29296, -0.40703], [53.96119, -1.09768]

travelMode: truck

routeOutputOptions": ["routePath", "itinerary"]

optimizeRoute: short

maxRouteCount: 1

Response: [{"Type":"FeatureCollection","Features":[]}]

Query AI answer: "The behavior is consistent with Azure Maps Route Directions returning no viable route when the constraints (mode, optimization, vehicle/truck settings, or waypoint order) make the trip impossible or invalid. When that happens, the service can return a valid GeoJSON wrapper (FeatureCollection) with an empty features array".

Previously this would actually return an error with "Invalid Route" or something to that effect. Can I just double check that this is no longer the case?

0 comments No comments

Sign in to comment

2 answers

  1. IoTGirl 3,961 Reputation points Microsoft Employee Moderator

    Hi Andrew,

    The 200 response indicates the co-ordinates were valid but that no "Truck" route could be found. We have a sample at https://samples.azuremaps.com/?search=truck&sample=car-vs-truck-route that gives both a truck and car route to demonstrate.

    Have you tried to change the default settings for the truck based on your real vehicle and load constraints?

    Default I only get the red route but if I change the settings I get a green one (Truck)

    👁 User's image

    Sincerely,

    IoTGirl

    (MIcrosoft Maps Team Member)

    0 comments No comments

    Sign in to comment
  2. Amira Bedhiafi 42,941 Reputation points MVP Volunteer Moderator

    Hello Andrew !

    Thank you for posting on MS Learn Q&A.

    Try to check the waypoint coordinate order. The new API uses GeoJSON, so coordinates must be sent as [longitude, latitude], not [latitude, longitude].

    The coordinates in the question appear to be York / Scarborough style latitude longitude pairs:

    [53.96119, -1.09768],
    [54.29296, -0.40703],
    [53.96119, -1.09768]
    

    For Azure Maps Route Directions they should be:

    [-1.09768, 53.96119],
    [-0.40703, 54.29296],
    [-1.09768, 53.96119]
    

    If sent in the original order, Azure Maps interprets them as longitude 53.x and latitude -1.x, which places the points somewhere completely different and likely not on a routable road network. That can explain the empty FeatureCollection.

    Regarding the empty features array, the current API doc defines a successful response as a GeoJSON FeatureCollection, and errors are returned separately as Maps error responses. I would not rely only on anInvalid Route error message for no-route cases. In client code, treat 200 OK with features: [] as no route returned / not routable and handle it explicitly.

    So try to swap the coordinate order first then retest.

    1. Andrew Martin 20 Reputation points

      The coordinates are being sent correctly in the API (York / Scarborough) if I change the vehicle type to car it routes perfectly. Issue is only with truck mode.


    Sign in to comment
Sign in to answer

Your answer