Geolocation
Get the device's GPS position once or stream live location updates.
Get started
Readings are delivered on the location event as a "latitude,longitude" string or an object with latitude and longitude, so subscribe before you call. Request the location permission first.
Get the current position
Read the device's latest fix. The reading arrives on the location event. Start tracking first — without it there's no fix to read yet.
Follow the device while the app is open
Start foreground tracking to keep the device's position up to date, then read it whenever you need it. Call stopForegroundTracking() to end it.
Tracking keeps the fix fresh; it doesn't push updates to your page. Poll getCurrentPosition() for each reading you want.
Stop a foreground stream
Stop an active foreground stream.
Keep tracking in the background
Keep receiving location updates while the app is backgrounded. On a successful start, backgroundLocationEnabled fires with { enabled, alreadyRunning, reason }.
Android only — wrap the call in try/catch.
Stop background tracking
Stop background updates. On a successful stop, backgroundLocationDisabled fires with { enabled }. Android only — wrap the call in try/catch.
Events
All position data arrives on events. bdk.on(...) returns an unsubscribe function.
location— every position reading (one-shot or streamed): a"latitude,longitude"string or an object withlatitudeandlongitude.backgroundLocationEnabled—{ enabled, alreadyRunning, reason }.backgroundLocationDisabled—{ enabled }.