Overview
Background location tracking enables your app to monitor device location in real-time, even when the app is minimized or the phone is locked. This feature is essential for delivery apps, fitness trackers, fleet management, and any application requiring continuous location monitoring.
Prerequisites
Despia Configuration
-
Open your Despia project
-
Navigate to Add-ons
-
Enable Background location tracking
-
Rebuild and republish your application (required for initial setup only)
-
Wait for the app to appear in TestFlight or Android Beta
WeWeb Setup
-
Install the Despia plugin from WeWeb Marketplace
-
Verify installation: Assets → Library → check for "Despia Provider"
Implementation Steps
Step 1: Add Despia Plugin Component
-
Click Add in WeWeb editor
-
Navigate to Assets panel
-
Drag Despia plugin to the top of your page
Step 2: Create Location Variable
-
Create a new variable named "location"
-
Set type to Object
-
Set example structure / or leave empty
{ "latitude": null, "longitude": null, "accuracy": null, "altitude": null, "altitudeAccuracy": null, "heading": null, "speed": null, "timestamp": null, "watchId": null }
Step 3: Add Start Tracking Button
-
Add a button element labeled "Start Background Location"
-
Go to Workflows → Add "On click" workflow
-
Add action: Execute component action
-
Component: Despia plugin
-
Action: "Start background location tracking"
-
Enable GPS: Yes (for higher accuracy)
-
Timeout: 5000 milliseconds (recommended default)
-
Step 4: Add Stop Tracking Button
-
Add another button labeled "Stop Background Location"
-
Go to Workflows → Add "On click" workflow
-
Add action: Execute component action
-
Component: Despia plugin
-
Action: "Stop background location tracking"
-
Step 5: Handle Location Updates
-
Select the Despia plugin component
-
Go to Workflows → Add new workflow
-
Change trigger to "On location change"
-
Add action: Change variable value
-
Variable: Select "location"
-
Value: Bind to
Event
(contains all location data)
-
Location Data Structure
The location event provides comprehensive data:
{
"latitude": 33.123456,
"longitude": -117.123456,
"altitude": 100.5,
"accuracy": 5, // meters
"altitudeAccuracy": 10, // meters
"heading": 180, // degrees
"speed": 15.5, // meters/second
"timestamp": 1234567890,
"watchId": "abc123"
}
Performance Considerations
Update Frequency
-
Location updates fire with high frequency (every slight movement)
-
Consider implementing debouncing for API calls
-
Cache updates for batch processing
Backend Integration Options
API with Debouncing (Recommended for most apps):
Add debouncing logic to prevent excessive API calls
Buffer updates for 10-30 seconds before sending
WebSockets (Best for real-time requirements):
-
Native WebSocket support in WeWeb
-
Works with Xano, Supabase real-time features
-
Ideal for live tracking applications
Battery Optimization
-
High GPS accuracy impacts battery life
-
Consider adjustable accuracy based on use case
-
Implement smart tracking intervals
Background Behavior
-
App minimized: Tracking continues
-
Phone locked: Tracking continues
-
App in background: Tracking continues
-
App force-closed: Tracking stops
Note: Background tracking requires the add-on enabled in Despia, not just WeWeb configuration.
Publishing & Updates
-
Initial setup requires app rebuild (for enabling add-on)
-
Subsequent changes in WeWeb use over-the-air updates
-
No App Store resubmission for tracking logic changes
-
Updates available immediately to all users
Common Use Cases
Delivery & Logistics
-
Real-time driver tracking
-
Route optimization
-
Delivery confirmation
Fitness & Health
-
Running/cycling route tracking
-
Distance and speed calculation
-
Workout history
Field Services
-
Employee location monitoring
-
Time tracking at job sites
-
Route verification
Transportation
-
Ride-sharing driver tracking
-
Public transit tracking
-
Fleet management
Best Practices
-
User Consent: Always request explicit permission
-
Privacy Policy: Clearly explain location data usage
-
Battery Warnings: Inform users about battery impact
-
Selective Tracking: Only track when necessary
-
Data Security: Encrypt location data transmission
-
Compliance: Follow GDPR, CCPA regulations
Troubleshooting
Location not updating:
-
Verify background location is enabled in Despia
-
Check device location permissions
-
Ensure GPS is enabled on device
Too many updates:
-
Implement debouncing
-
Adjust timeout settings
-
Consider using WebSockets
Battery drain:
-
Reduce GPS accuracy when high precision not needed
-
Implement smart tracking schedules
-
Stop tracking when not needed
For additional support or questions, please contact our support team at support@despia.com