import { NavigationManager } from "@/path-to/navigation-manager";
The NavigationManager class is responsible for handling real-time navigation, including location tracking, heading updates, route progress, and arrival detection.
Ensure you have expo-location installed:
sh
yarn add expo-location
or
sh
npm install expo-location
tsx
import { NavigationManager } from "@/path-to/navigation-manager";
const navigationManager = new NavigationManager();
new NavigationManager()Creates an instance of NavigationManager and initializes location tracking.
initializeRoute(destination: Destination)Initializes a new route to the specified destination.
Parameters:
destination: { latitude: number, longitude: number } - The target location.handleRouteReady(result: any)Processes the received route data and extracts navigation steps.
Parameters:
result: any - The route data from the navigation API.endNavigation()Stops the navigation and clears the route information.
setCallbacks(callbacks: Callbacks)Registers callback functions for location updates, heading updates, route changes, arrival detection, and more.
Parameters:
callbacks: { onLocationUpdate?: Function, onHeadingUpdate?: Function, ... }cleanup()Removes all active location and heading subscriptions.
getCurrentStep(): numberReturns the current step index of the navigation route.
getRouteInfo(): RouteInfo | nullReturns the active route information.
isNearDestinationStatus(): booleanIndicates whether the user is near the destination.
onLocationUpdate(location: LocationObject)Triggered when the user's location changes.
onHeadingUpdate(heading: number)Triggered when the user's heading changes.
onRouteUpdate(routeInfo: RouteInfo | null, stepIndex?: number)Triggered when the route updates or a new step is reached.
onArrival(distance: string, duration: string)Triggered when the user arrives at the destination.
onNearDestinationChange(isNear: boolean)Triggered when the user is within 3 miles of the destination.
onMapRotationUpdate(rotation: number)Triggered when the map should rotate based on the user's direction.
calculateDistance(point1, point2): numberCalculates the distance between two geographical points in meters.
calculateBearing(start, end): numberComputes the bearing angle between two geographical points.
tsx
const navigationManager = new NavigationManager();
navigationManager.setCallbacks({
onLocationUpdate: (location) => console.log("New location:", location),
onRouteUpdate: (routeInfo) => console.log("Route updated:", routeInfo),
onArrival: (distance, duration) => console.log("Arrived!", distance, duration),
});
MIT