Search code examples
azure-maps

Azure Maps - Route directions across the ocean


I am trying to calculate the distance between two coordinates across the Atlantic Ocean using the Azure Maps routing service. Unfortunately I always get the following error:

    {
        "error": {
            "code": "400 BadRequest",
            "message": "Engine error while executing route request: NO_ROUTE_FOUND"
        }
    }

Does Azure Maps support the calculation or am I doing something wrong?

This is the example of the request which returns the error: https://atlas.microsoft.com/route/directions/json?api-version=1.0&subscription-key=XXXX-XXXX-XXXX-XXXX&query=29.757290,-95.357379:48.876584,2.339379

The coordinates are valid. 29.757290,-95.357379 is Houston (Texas, USA) 48.876584,2.339379 is Paris (France, Europe)

Can anybody help? Thanks.


Solution

  • The routing service calculates routes along roads, so it will fail to calculate a route that crosses the Atlantic Ocean. If you want to calculate the straight line (geodesic) path across between two points you have multiple options:

    1. Use the great circle distance service: https://learn.microsoft.com/en-us/rest/api/maps/spatial/get-great-circle-distance?tabs=HTTP
    2. If using the Azure Maps Web SDK, there is a built in math library. Use atlas.math.getDistanceTo function: https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas.math?view=azure-maps-typescript-latest#azure-maps-control-atlas-math-getdistanceto
    3. Use the Haversine Formula directly in your code: https://rosettacode.org/wiki/Haversine_formula (this link provides the formula in over 120 programming languages).