CruciDrive’s geolocation system is purpose-built for the compact geography of Crucita, Ecuador. Tricimoto drivers emit their GPS coordinates every 5 seconds from the mobile app; the backend persists each update to theDocumentation 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.
tricimotos table using a PostGIS GEOGRAPHY(POINT, 4326) column and simultaneously broadcasts the position to every passenger subscribed to that driver’s sector room. Passengers see nearby tricimotos move in real time on the map without polling the REST API.
Geographic Sectors
Crucita’s operational area is divided into five fixed sectors. Each sector has a unique string ID, a display name, a center coordinate used to focus the map, and a marker color for the UI:| Sector ID | Name | Center Coordinates |
|---|---|---|
centro | Centro de Crucita | -1.0448, -80.5432 |
playa | Malecón / Playa | -1.0470, -80.5485 |
las_gilces | Las Gilces | -1.0395, -80.5350 |
los_arenales | Los Arenales | -1.0520, -80.5410 |
san_jacinto | San Jacinto | -1.0600, -80.5370 |
Fixed Tariff Grid
Rather than calculating dynamic fares from GPS distance, CruciDrive uses a pre-computed tariff matrix between sector pairs. This eliminates surge pricing complexity and makes fares transparent to passengers before they request a ride. Fares are symmetric — the cost from A to B equals the cost from B to A.| Origin → Destination | Price (USD) | Distance (km) | Est. Time (min) |
|---|---|---|---|
| Centro → Playa | $1.50 | 1.2 | 5 |
| Centro → Las Gilces | $2.00 | 2.0 | 8 |
| Centro → Los Arenales | $1.75 | 1.5 | 6 |
| Centro → San Jacinto | $2.40 | 3.2 | 10 |
| Playa → Las Gilces | $2.50 | 3.0 | 12 |
| Playa → Los Arenales | $1.50 | 1.0 | 4 |
| Playa → San Jacinto | $2.20 | 2.8 | 9 |
| Las Gilces → Los Arenales | $2.00 | 2.2 | 8 |
| Las Gilces → San Jacinto | $3.00 | 4.0 | 15 |
| Los Arenales → San Jacinto | $1.50 | 1.3 | 5 |
PostGIS Storage
Driver positions and ride coordinates are stored as native PostGIS geography columns using the WGS84 (EPSG:4326) coordinate reference system:tricimotos.ubicacion_actual—GEOGRAPHY(POINT, 4326): updated on everyupdate_locationSocket eventviajes.origen—GEOGRAPHY(POINT, 4326): set at ride creation from the passenger’s chosen origin sector centerviajes.destino—GEOGRAPHY(POINT, 4326): set at ride creation from the passenger’s chosen destination sector center
toWKT utility in backend/src/utils/geo.js converts a { lng, lat } pair to PostGIS Well-Known Text before any database write:
POINT(longitude latitude), so lng is always the first argument.
Socket.io Sector Rooms
Each geographic sector maps to a Socket.io room namedsector:{sectorId}. When a passenger opens the map screen, their client emits a join_sector event with the current sector ID; the server calls socket.join('sector:playa') (for example), subscribing them to all driver updates in that area.
When a driver emits update_location, the server:
- Validates that the socket’s role is
conductor - Writes the new position to
tricimotos.ubicacion_actualvia a PostGIS WKT update - Broadcasts a
location_updatedevent to all other sockets insector:{sectorId}
Driver Location Updates
Theupdate_location event payload sent by the driver client:
location_updated event payload broadcast to passengers in the sector room:
estado are disponible, ocupado, and inactivo, matching the CHECK constraint on tricimotos.estado.
Nearest Sector Helper
ThefindNearestSector function in sectors.ts uses Euclidean distance over sector center coordinates to snap a raw GPS coordinate to the closest sector. This is sufficient for Crucita’s scale — the entire operational area spans roughly 4 km — and avoids the overhead of spherical distance calculations:
Location Config
All geolocation timing and accuracy parameters are centralized inLOCATION_CONFIG inside frontend/src/constants/config.ts:
distanceFilterMeters: 10 setting means the device OS suppresses GPS events when the driver has moved less than 10 meters since the last emission, cutting redundant network traffic during idle periods.
The
driverDataLimitBytes in APP_CONFIG is set to 15 MB per day (15 * 1024 * 1024). The 5-second update interval combined with the 10-meter distance filter is calibrated to keep a full driving shift well within this budget on typical Ecuadorian mobile data plans.