Skip to content

CalculateRouteMatrix

Source: src/AWS/GeoRoutes/CalculateRouteMatrix.ts

Runtime binding for geo-routes:CalculateRouteMatrix — compute travel time and distance for all pairs of origins to destinations in one call (an origin-destination cost matrix), e.g. rank the nearest store for each customer.

geo-routes is a standalone, pay-per-call Amazon Location API with no resource to manage: the binding takes no arguments and grants the function geo-routes:CalculateRouteMatrix. Requests and responses are raw distilled types (positions are [longitude, latitude] pairs). The matrix requires a RoutingBoundary — a geometry that contains all origins and destinations, or { Unbounded: true }.

Provide the CalculateRouteMatrixHttp implementation layer on the Function effect (.pipe(Effect.provide(AWS.GeoRoutes.CalculateRouteMatrixHttp))), bind in the init phase, then call the client at runtime.

// init
const calculateRouteMatrix = yield* AWS.GeoRoutes.CalculateRouteMatrix();
// runtime — positions are [longitude, latitude]
const result = yield* calculateRouteMatrix({
Origins: [
{ Position: [-122.339, 47.61] },
{ Position: [-122.335, 47.608] },
],
Destinations: [
{ Position: [-122.201, 47.61] },
{ Position: [-122.313, 47.62] },
],
RoutingBoundary: {
Geometry: { Circle: { Center: [-122.3, 47.61], Radius: 30_000 } },
},
});
const secondsFromFirstOriginToFirstDestination =
result.RouteMatrix[0]?.[0]?.Duration;