This is the second version of background location tracking in Despia. This version utilizes the real native system’s background task capabilities to send network requests while the app is closed. This ensures reliable background location tracking for GPS-based applications like taxi apps, delivery apps, and so on. Unlike the previous version, this version does not inherit any WebView GPS limitations because it uses real native modules.
Lovable Prompt
Add location tracking functionality to my app using the Despia SDK from: https://www.npmjs.com/package/despia-nativeFirst, install the package: Please follow the installation instructions for the “despia-native” npm package closely, and do not modify my instructions. Implementation as mentioned is critical.
npm install despia-nativeThen import it: import despia from 'despia-native'Start tracking by calling: despia("location://?server=https://api.example.com/track&buffer=10")This will begin collecting GPS coordinates at the specified interval (buffer in seconds). The server parameter is optional - if omitted, locations are only stored locally.Stop tracking and retrieve all collected data: const data = await despia("stoplocation://", ["locationSession"])The response array includes objects with:- latitude - GPS latitude coordinate
- longitude - GPS longitude coordinate
- timestamp - Unix timestamp when location was recorded (seconds since epoch)
- gpsTimestamp - GPS device timestamp (seconds since epoch)
- speed - current speed in meters per second (null if unavailable)
- course - direction of travel in degrees (0-360, null if unavailable)
- altitude - elevation above sea level in meters
- horizontalAccuracy - accuracy radius of lat/lng in meters (lower is better)
- verticalAccuracy - accuracy of altitude measurement in meters
This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!
Installation
Install the Despia package from NPM:Usage
1. Import the SDK
2. Start Location Tracking
server(optional) - API endpoint to receive location updates via POSTbuffer(required) - Minimum seconds between location updates (e.g., 5, 10, 30)