Skip to main content
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: 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
Use this to track user movements, calculate distances, analyze travel patterns, or implement location-based features. The buffer interval prevents excessive battery drain by controlling update frequency.
This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!
Please follow the installation instructions for the “despia-native” npm package closely, and do not modify my instructions. Implementation as mentioned is critical.
How it Works: Despia activates the device’s native GPS and location services to continuously monitor the user’s position. Location updates are collected at the interval specified by the buffer parameter (in seconds). Each update is optionally sent to your server endpoint and always stored locally in an array. When tracking stops, all collected location points are returned to your JavaScript code for processing or display.

Installation

Install the Despia package from NPM:

Usage

1. Import the SDK

2. Start Location Tracking

Parameters:
  • server (optional) - API endpoint to receive location updates via POST
  • buffer (required) - Minimum seconds between location updates (e.g., 5, 10, 30)

3. Stop Tracking and Retrieve Data

4. Example Response

6. Calculate Distance and Analyze Movement

Resources

NPM Package View full NPM documentation for additional configuration options

Lovable Integration

This SDK is optimized for Lovable’s prompt-based AI builder, enabling quick integration of native rewarded ads into your generated apps. For additional support or questions, please contact our support team at support@despia.com