react-native-background-geolocation
Sophisticated, battery-conscious background-geolocation with motion-detection
Top Related Projects
Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
React native geolocation service for iOS and android
Geolocation APIs for React Native
React Native Mapview component for iOS + Android
Quick Overview
React Native Background Geolocation is a comprehensive location tracking module for React Native applications. It offers sophisticated background location tracking with battery-conscious technology, supporting both iOS and Android platforms. The library provides a rich set of features for tracking user location, including geofencing, motion detection, and trip logging.
Pros
- Highly configurable with numerous options for fine-tuning location tracking behavior
- Battery-efficient implementation, minimizing power consumption
- Robust cross-platform support for both iOS and Android
- Extensive documentation and active community support
Cons
- Complex setup process, especially for iOS due to required permissions and capabilities
- Potential learning curve for developers new to background location tracking concepts
- Premium features require a paid license
- Large package size due to comprehensive feature set
Code Examples
- Basic setup and initialization:
import BackgroundGeolocation from "react-native-background-geolocation";
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
}, (state) => {
console.log("BackgroundGeolocation is ready: ", state);
});
- Starting and stopping location tracking:
// Start tracking
BackgroundGeolocation.start();
// Stop tracking
BackgroundGeolocation.stop();
- Listening for location updates:
BackgroundGeolocation.onLocation(location => {
console.log("[Location] ", location);
}, error => {
console.log("[Location Error] ", error);
});
- Setting up a geofence:
BackgroundGeolocation.addGeofence({
identifier: "Home",
radius: 200,
latitude: 45.51921926,
longitude: -73.61678581,
notifyOnEntry: true,
notifyOnExit: true
});
Getting Started
-
Install the package:
npm install react-native-background-geolocation -
For iOS, add the following to your
Info.plist:<key>NSLocationAlwaysUsageDescription</key> <string>Location required in background</string> <key>NSLocationWhenInUseUsageDescription</key> <string>Location required when app is in use</string> -
For Android, add the following permissions to your
AndroidManifest.xml:<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> -
Initialize and configure the plugin in your app as shown in the first code example above.
Competitor Comparisons
Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
Pros of react-native-background-geolocation (mauron85)
- Open-source and free to use without licensing restrictions
- Simpler setup and configuration process
- Lighter weight with fewer dependencies
Cons of react-native-background-geolocation (mauron85)
- Less frequent updates and maintenance
- Fewer advanced features compared to the transistorsoft version
- Limited documentation and community support
Code Comparison
react-native-background-geolocation (mauron85):
import BackgroundGeolocation from 'react-native-background-geolocation';
BackgroundGeolocation.configure({
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
distanceFilter: 50,
notificationTitle: 'Background tracking',
notificationText: 'enabled',
debug: true,
startOnBoot: false,
stopOnTerminate: false,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 10000,
fastestInterval: 5000,
activitiesInterval: 10000,
});
react-native-background-geolocation (transistorsoft):
import BackgroundGeolocation from "react-native-background-geolocation";
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
debug: true,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopTimeout: 1,
url: 'http://yourserver.com/locations',
batchSync: false,
autoSync: true,
headers: {
"X-FOO": "bar"
},
params: {
"auth_token": "maybe_your_server_authenticates_via_token_YES?"
}
});
Both libraries offer similar core functionality for background geolocation in React Native applications. The mauron85 version is more straightforward and easier to set up, while the transistorsoft version provides more advanced features and configuration options.
React native geolocation service for iOS and android
Pros of react-native-geolocation-service
- Lightweight and focused solely on geolocation services
- Simpler setup and integration process
- Free and open-source without licensing restrictions
Cons of react-native-geolocation-service
- Limited background tracking capabilities
- Fewer advanced features like geofencing or motion detection
- Less comprehensive documentation and community support
Code Comparison
react-native-geolocation-service:
import Geolocation from 'react-native-geolocation-service';
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
react-native-background-geolocation:
import BackgroundGeolocation from "react-native-background-geolocation";
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
}, (state) => {
console.log("- BackgroundGeolocation is ready: ", state);
});
The code comparison shows that react-native-geolocation-service offers a simpler API for basic geolocation tasks, while react-native-background-geolocation provides more advanced configuration options for persistent background tracking. The latter also includes features like automatic start on device boot, which is not available in the simpler library.
Geolocation APIs for React Native
Pros of react-native-geolocation
- Lightweight and focused solely on basic geolocation functionality
- Simpler setup and integration process
- Free and open-source without licensing restrictions
Cons of react-native-geolocation
- Lacks advanced background tracking capabilities
- Limited battery optimization features
- Fewer configuration options for fine-tuning location services
Code Comparison
react-native-geolocation:
import Geolocation from '@react-native-community/geolocation';
Geolocation.getCurrentPosition(
position => {
console.log(position);
},
error => console.log(error),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
react-native-background-geolocation:
import BackgroundGeolocation from "react-native-background-geolocation";
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
}, (state) => {
console.log("- BackgroundGeolocation is ready: ", state);
});
The code comparison shows that react-native-geolocation offers a simpler API for basic location tracking, while react-native-background-geolocation provides more advanced configuration options for continuous background tracking and power management. The latter offers more control over the geolocation process, making it suitable for apps requiring persistent location monitoring.
React Native Mapview component for iOS + Android
Pros of react-native-maps
- Focused on map rendering and interaction, providing a comprehensive set of map-related features
- Supports both iOS and Android platforms with a unified API
- Offers customizable map styles and markers
Cons of react-native-maps
- Limited to map-related functionality, lacking background location tracking capabilities
- May require additional libraries for advanced geolocation features
- Higher learning curve for complex map interactions
Code Comparison
react-native-maps:
import MapView, { Marker } from 'react-native-maps';
<MapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
<Marker coordinate={{ latitude: 37.78825, longitude: -122.4324 }} />
</MapView>
react-native-background-geolocation:
import BackgroundGeolocation from 'react-native-background-geolocation';
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
}, (state) => {
console.log('BackgroundGeolocation is ready: ', state);
});
The code examples highlight the different focus areas of each library. react-native-maps emphasizes map rendering and marker placement, while react-native-background-geolocation concentrates on configuring and managing background location tracking.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Background Geolocation for React Native & Expo
The most sophisticated background location-tracking & geofencing SDK with battery-conscious motion-detection intelligence for iOS and Android.
The SDK uses motion-detection APIs (accelerometer, gyroscope, magnetometer) to detect when the device is moving or stationary:
- Moving â location recording starts automatically at the configured
distanceFilter(metres) - Stationary â location services turn off automatically to conserve battery
[!IMPORTANT] This is
v5. For the previous version seev4.x.v4.xlicense keys do not work withv5â log in to the Customer Dashboard to generate av5key. See the Migration Guide for details.
:books: Documentation
React Native
Expo
:key: Licensing
[!TIP] The SDK is fully functional in
DEBUGbuilds â no license required. Try before you buy.
A license is required only for RELEASE builds on Android.
Purchase a license
:open_file_folder: Example Apps
See /example â example apps are included in this repo.
ð¦ SDK availability
| Platform | Package |
|---|---|
| This repo | |
| This repo | |
flutter_background_geolocation | |
@transistorsoft/capacitor-background-geolocation | |
cordova-background-geolocation-lt | |
background-geolocation | |
background-geolocation |
MIT © Transistor Software
Top Related Projects
Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
React native geolocation service for iOS and android
Geolocation APIs for React Native
React Native Mapview component for iOS + Android
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot