CruciDrive uses two complementary location-related hooks.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DavidCevallos15/Crucidrive---APP/llms.txt
Use this file to discover all available pages before exploring further.
useLocation manages expo-location permissions and returns the device’s current GPS coordinates — optionally enabling continuous tracking for the driver console. useMapRegion takes those coordinates and computes a MapRegion object compatible with react-native-maps, falling back to the default Crucita region when GPS is unavailable.
expo-location permissions must be declared in app.json. CruciDrive registers both foreground and background location permissions under the expo-location plugin, with Spanish-language permission strings shown to the user on iOS and Android.useLocation
useLocation wraps expo-location to handle the full permissions + position lifecycle. It stores coordinates and the detected sector in the Zustand useLocationStore, making the last known position available app-wide without prop-drilling.
Signature
When
true, the hook automatically calls startTracking() on mount and stops the watch subscription on unmount. Set to true on the driver console screen; leave false (default) on the passenger map to use one-shot position reads instead.Return values
| Property | Type | Description |
|---|---|---|
userCoords | { lat: number; lng: number } | null | Most recent GPS coordinates from the Zustand location store |
currentSectorId | string | null | ID of the Crucita sector nearest to userCoords, computed by findNearestSector |
hasPermission | boolean | Whether foreground location permission has been granted |
isTracking | boolean | true while a watchPositionAsync subscription is active |
requestPermissions | () => Promise<boolean> | Requests foreground location permission; returns true if granted |
requestBackgroundPermissions | () => Promise<boolean> | Requests background location permission — required for driver tracking when the app is backgrounded |
getCurrentPosition | () => Promise<{ lat: number; lng: number } | null> | Reads the current position once using Location.getCurrentPositionAsync() |
startTracking | () => Promise<void> | Starts a watchPositionAsync subscription with the configured interval and distance filter |
stopTracking | () => void | Removes the watch subscription and sets isTracking to false |
How tracking works
WhenstartTracking() is called, it creates a Location.watchPositionAsync subscription using the values from LOCATION_CONFIG:
findNearestSector, which uses a Euclidean distance comparison across the five Crucita sectors to determine which sector the driver is currently in.
useMapRegion
useMapRegion is a thin memoization wrapper that converts a Coordinates object (or null) into the MapRegion shape expected by react-native-maps’ <MapView region={...} /> prop.
Signature
The
{ lat, lng } object from useLocation. Pass null to fall back to the default Crucita region.Return type
userCoords is null — GPS denied or not yet resolved — the hook returns LOCATION_CONFIG.defaultRegion, centring the map on Crucita:
useMemo and only recomputes when userCoords changes, preventing unnecessary <MapView> re-renders.
Location config constants
Both hooks are governed by theLOCATION_CONFIG object in src/constants/config.ts:
| Constant | Value | Effect |
|---|---|---|
driverUpdateIntervalMs | 5000 | Drivers push a GPS update to the server every 5 seconds |
distanceFilterMeters | 10 | A GPS event is only emitted after the device has moved at least 10 metres |
defaultRegion.latitude | -1.0448 | Map fallback latitude — Crucita town centre |
defaultRegion.longitude | -80.5432 | Map fallback longitude — Crucita town centre |
defaultRegion.latitudeDelta | 0.02 | ~2.2 km vertical map span |
defaultRegion.longitudeDelta | 0.02 | ~2.2 km horizontal map span |
Usage — passenger map screen
For passengers, a single position read on mount is sufficient.enableTracking stays false: