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

    Function useRoute

    • Hook to calculate a route from an origin to the closest of one or more destinations. The route updates as the user moves when the origin is UserLocation, and when the map updates. It is recreated when the origin, destinations, or options change.

      Pass a list of options to calculate one route for each. The results come back in the same order, and every update holds routes calculated from the same location.

      Parameters

      Returns RouteResult

      A RouteResult object with status "idle", "pending", "success", or "error", or one per option when options is a list

      const routeResult = useRoute(mapLoadResult, {
      origin: UserLocation,
      destinations: [{ latitude: 52.8982, longitude: -1.8463 }]
      });

      if (routeResult.status === "success") {
      console.log(`Distance: ${routeResult.route.distance} meters`);
      }

      const [standard, accessible] = useRoute(mapLoadResult, {
      origin: UserLocation,
      destinations: [{ latitude: 52.8982, longitude: -1.8463 }],
      options: [RouteOptions.none(), RouteOptions.avoidReducedAccessibility()]
      });
    • Hook to calculate a route from an origin to the closest of one or more destinations. The route updates as the user moves when the origin is UserLocation, and when the map updates. It is recreated when the origin, destinations, or options change.

      Pass a list of options to calculate one route for each. The results come back in the same order, and every update holds routes calculated from the same location.

      Type Parameters

      Parameters

      • mapLoadResult: MapLoadResult

        The result from the useMap hook

      • params: UseRouteParams & { options: Options }

        Route parameters including origin, destinations, and optional configuration

      Returns { [Index in string | number | symbol]: RouteResult }

      A RouteResult object with status "idle", "pending", "success", or "error", or one per option when options is a list

      const routeResult = useRoute(mapLoadResult, {
      origin: UserLocation,
      destinations: [{ latitude: 52.8982, longitude: -1.8463 }]
      });

      if (routeResult.status === "success") {
      console.log(`Distance: ${routeResult.route.distance} meters`);
      }

      const [standard, accessible] = useRoute(mapLoadResult, {
      origin: UserLocation,
      destinations: [{ latitude: 52.8982, longitude: -1.8463 }],
      options: [RouteOptions.none(), RouteOptions.avoidReducedAccessibility()]
      });