Examples
Complete integration patterns for real-world use cases. Each example is production-ready — copy, adjust, and ship.
Fleet / Delivery Tracking
Continuous tracking with adaptive distance filter, native HTTP posting, and automatic offline buffering. Ideal for logistics and delivery apps.
import { addListener, configure, start } from '@bglocation/react-native';
await configure({
distanceFilter: 'auto',
autoDistanceFilter: {
targetInterval: 10,
minDistance: 10,
maxDistance: 500,
},
desiredAccuracy: 'high',
heartbeatInterval: 30,
http: {
url: 'https://api.fleet.com/vehicle/location',
headers: { Authorization: 'Bearer <token>' },
buffer: { maxSize: 2000 },
},
});
addListener('onHttp', (event) => {
if (!event.success) {
console.warn('Buffered:', event.bufferedCount);
}
});
await start();Fitness / Running App
High-frequency tracking with in-memory processing for pace, route, and progress stats. Low distance filter for detailed route polylines.
import {
addListener,
configure,
start,
} from '@bglocation/react-native';
import type { Location } from '@bglocation/react-native';
const route: Location[] = [];
await configure({
distanceFilter: 5,
desiredAccuracy: 'high',
heartbeatInterval: 10,
locationUpdateInterval: 3000,
});
addListener('onLocation', (location) => {
route.push(location);
updateMapPolyline(route);
});
await start();Geofencing — Points of Interest
Register circular regions and react to enter, exit, and dwell transitions. Great for location-based notifications and triggered actions.
import {
addGeofence,
addListener,
configure,
start,
} from '@bglocation/react-native';
await configure({
distanceFilter: 50,
desiredAccuracy: 'balanced',
heartbeatInterval: 60,
});
await addGeofence({
identifier: 'office',
latitude: 52.2297,
longitude: 21.0122,
radius: 100,
notifyOnEntry: true,
notifyOnExit: true,
});
addListener('onGeofence', (event) => {
console.log(event.identifier, event.action);
});
await start();Attendance / Check-In System
Combine geofencing with HTTP posting for automatic workplace check-in and check-out. Uses geofence extras to attach metadata like building and floor.
import {
addGeofence,
addListener,
configure,
start,
} from '@bglocation/react-native';
await configure({
distanceFilter: 100,
desiredAccuracy: 'balanced',
heartbeatInterval: 120,
http: {
url: 'https://api.company.com/attendance/checkin',
headers: { Authorization: 'Bearer <token>' },
},
});
// Register workplace geofence
await addGeofence({
identifier: 'headquarters',
latitude: 52.2297,
longitude: 21.0122,
radius: 150,
notifyOnEntry: true,
notifyOnExit: true,
extras: { building: 'HQ', floor: '3' },
});
addListener('onGeofence', (event) => {
if (event.action === 'enter') {
recordCheckIn(event.identifier, event.extras);
} else if (event.action === 'exit') {
recordCheckOut(event.identifier, event.extras);
}
});
await start();Recommended Configuration by Use Case
| Use Case | distanceFilter | heartbeat | accuracy | Key Features |
|---|---|---|---|---|
| Fleet tracking | auto | 30s | high | HTTP + buffer |
| Fitness | 5m | 10s | high | In-memory route |
| Geofencing | 50m | 60s | balanced | Geofence regions |
| Attendance | 100m | 120s | balanced | Geofence + HTTP |