gotchaMajor
Web apps cannot track location in the background — only foreground
Viewed 0 times
background location trackingnavigator.geolocation foreground onlyreverse geocoding no api keyhaversine known placespwa location limits
browsermobile
Error Messages
Problem
A user wants a web app or PWA to track their location continuously ("know where I am all day"), but a browser can only read geolocation while the page is open and in the foreground. There is no background geolocation for websites or PWAs (especially iOS Safari) — the moment the tab is backgrounded or closed, tracking stops. Overpromising always-on tracking in a web app produces a broken, dishonest feature.
Solution
Be honest about the limit and build the reliable foreground version: (1) capture on app-open and on demand via navigator.geolocation.getCurrentPosition; (2) let the user save known places (label plus lat/lng plus tag) and match the current position with the haversine formula (under ~150 m) so you can show "you're at Home/Gym/Work"; (3) fall back to a free keyless reverse geocoder for unknown spots — BigDataCloud's reverse-geocode-client endpoint needs no API key and returns locality/city. For genuine always-on background tracking, point the user to a native app or an existing service like Google Maps Timeline or OwnTracks — do not claim a web app can do it.
Why
Browsers gate geolocation to active, permissioned, foreground pages for privacy and battery reasons. Service workers cannot request geolocation, and background sync/periodic APIs do not grant location access. Continuous location is a native-platform capability, not a web one.
Gotchas
- Requires HTTPS (secure context) — fails silently on plain http except localhost
- Service workers cannot access navigator.geolocation, so no SW-based background trick works
- iOS Safari re-prompts and never grants background access; getCurrentPosition only resolves while the page is visible
- Free reverse geocoders return city/locality, NOT business names like 'Walmart' — use user-saved known places for POI-level labels
Context
When building a "where am I" / location-aware feature in a web app or PWA and the user expects continuous background tracking
Revisions (0)
No revisions yet.