Convert Figma logo to code with AI

transistorsoft logoreact-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection

2,896
445
2,896
41

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

  1. 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);
});
  1. Starting and stopping location tracking:
// Start tracking
BackgroundGeolocation.start();

// Stop tracking
BackgroundGeolocation.stop();
  1. Listening for location updates:
BackgroundGeolocation.onLocation(location => {
  console.log("[Location] ", location);
}, error => {
  console.log("[Location Error] ", error);
});
  1. Setting up a geofence:
BackgroundGeolocation.addGeofence({
  identifier: "Home",
  radius: 200,
  latitude: 45.51921926,
  longitude: -73.61678581,
  notifyOnEntry: true,
  notifyOnExit: true
});

Getting Started

  1. Install the package:

    npm install react-native-background-geolocation
    
  2. 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>
    
  3. 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" />
    
  4. 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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Background Geolocation for React Native

Background Geolocation for React Native & Expo

npm npm

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 see v4.x. v4.x license keys do not work with v5 — log in to the Customer Dashboard to generate a v5 key. See the Migration Guide for details.


:books: Documentation

React Native

Expo


:key: Licensing

[!TIP] The SDK is fully functional in DEBUG builds — 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

PlatformPackage
React NativeThis repo
ExpoThis repo
Flutterflutter_background_geolocation
Capacitor@transistorsoft/capacitor-background-geolocation
Cordovacordova-background-geolocation-lt
Swift / iOSbackground-geolocation
Kotlin / Androidbackground-geolocation

MIT © Transistor Software

NPM DownloadsLast 30 Days