@maplayr/react-native
    Preparing search index...

    Type Alias RouteResult

    RouteResult:
        | { error: null; route: null; status: "idle" }
        | { error: null; route: null; status: "pending" }
        | { error: null; route: Route; status: "success" }
        | { error: Error; route: null; status: "error" }

    Represents the result of calculating a route, with four possible states:

    • idle: There is nothing to calculate, because the origin is null or the map has not loaded
    • pending: The route is not available yet, for example while waiting for the user's location
    • success: The route was calculated
    • error: No route could be calculated

    The result updates as the route does. When the origin, destinations or options change, the previous result is kept until the new route has one, so a displayed route does not disappear.

    const routeResult = useRoute(mapLoadResult, { origin, destinations });

    switch (routeResult.status) {
    case "success":
    return <Text>{routeResult.route.distance} metres</Text>;
    case "error":
    return <Text>No route: {routeResult.error.message}</Text>;
    }