Battery-efficient location tracking with motion detection and native notifications.
npm install react-native-geo-activity-kitA production-grade, battery-efficient background tracking and activity recognition library for React Native.
This library is designed for apps that require reliable background location tracking and activity recognition. It combines Google Fused Location Provider with the Activity Recognition Transition API to create a Smart Tracking Engine that automatically adjusts GPS frequency based on user movement — ensuring high accuracy when moving and near-zero battery drain when stationary.
---
is_mock flag to detect spoofed locations.---
``bash`
npm install react-native-geo-activity-kitor
yarn add react-native-geo-activity-kit
---
Because this library runs continuously in the background, AndroidManifest.xml configuration is mandatory.
Open android/app/src/main/AndroidManifest.xml and add:
`xml
`
---
Inside the tag:
`xml
android:enabled="true"
android:exported="false"
android:foregroundServiceType="location" />
android:exported="false"
android:permission="com.google.android.gms.permission.ACTIVITY_RECOGNITION">
`
---
`javascript
import { PermissionsAndroid, Platform } from 'react-native';
async function requestPermissions() {
if (Platform.OS === 'android') {
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
PermissionsAndroid.PERMISSIONS.ACTIVITY_RECOGNITION,
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
]);
}
}
`
---
`javascript
import GeoKit from 'react-native-geo-activity-kit';
const startTracking = async () => {
await GeoKit.startForegroundService(
'Location Service Active',
'Tracking location in background',
9991
);
await GeoKit.startMotionDetector();
};
`
---
`javascript
import { useEffect } from 'react';
import GeoKit from 'react-native-geo-activity-kit';
useEffect(() => {
const locationSub = GeoKit.addLocationLogListener((event) => {
console.log(event.latitude, event.longitude);
if (event.is_mock) {
console.warn('FAKE GPS DETECTED');
}
});
const motionSub = GeoKit.addMotionListener((event) => {
console.log(event.activity, event.isMoving);
});
const gpsSub = GeoKit.addGpsStatusListener((event) => {
if (!event.enabled) {
console.error('GPS turned OFF');
}
});
return () => {
locationSub.remove();
motionSub.remove();
gpsSub.remove();
};
}, []);
`
---
`javascript`
GeoKit.fireGeofenceAlert('OUT', 'User');
GeoKit.fireGeofenceAlert('IN', 'User');
---
`javascript`
GeoKit.fireGenericAlert('New Task', 'You have a new site visit.', 1001);
---
`javascript``
GeoKit.cancelGenericAlert(1001);
---
| Method | Description |
|------|------------|
| startForegroundService | Starts persistent background service |
| stopForegroundService | Stops service |
| updateServiceNotification | Updates notification text |
---
| Method | Description |
|------|------------|
| startMotionDetector | Enables activity recognition |
| stopMotionDetector | Stops motion detection |
| setLocationUpdateInterval | Manual GPS override |
| registerGpsListener | Monitor GPS toggle |
---
- Android: SDK 29 (Android 10) to SDK 34 (Android 14)
- iOS: Not supported
---
---
MIT
---
Kartikey Mishra
Creator & Maintainer of React Native Geo Activity Kit