npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-gps-tracker

v0.1.2

Published

Background GPS tracking lib for React Native with support for IOS and Android

Downloads

473

Readme

react-native-gps-tracker

Background GPS tracking lib for React Native with support for IOS and Android

Installation

npm install react-native-gps-tracker

or:

yarn add react-native-gps-tracker

iOS setup

Install pods after adding the package:

cd ios
pod install

Add the required location, motion, and background mode entries to your app Info.plist:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your app needs location access in the background to track GPS trips.</string>

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your app needs location access while it is open to read the current GPS position.</string>

<key>NSMotionUsageDescription</key>
<string>Your app uses motion data to optimize GPS tracking while the device moves or stays still.</string>

<key>UIBackgroundModes</key>
<array>
  <string>location</string>
</array>

In Xcode, also enable the same background mode:

  1. Open your app workspace.
  2. Select your app target.
  3. Open Signing & Capabilities.
  4. Add Background Modes.
  5. Enable Location updates.

If your app needs tracking to resume after the process is relaunched, import the native module in AppDelegate.swift:

import GpsTracker

Then call restoreTrackingIfNeeded() from application(_:didFinishLaunchingWithOptions:) after your React Native setup:

GPSManager.shared.restoreTrackingIfNeeded()

This does not replace calling requestPermission() and startTracking() from JavaScript. It only restores native tracking if it was already enabled before the app process restarted.

Android setup

The library manifest declares the service, boot receiver, and required permissions, and React Native/Gradle should merge them into your app manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

The merged manifest also includes:

<service
  android:name="com.gpstracker.GpsTrackerLocationService"
  android:exported="false"
  android:foregroundServiceType="location"
  android:stopWithTask="false" />

<receiver
  android:name="com.gpstracker.GpsTrackerBootReceiver"
  android:enabled="true"
  android:exported="false">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
  </intent-filter>
</receiver>

If your app manifest uses strict manifest tooling or a custom manifest merge setup, copy the entries above into android/app/src/main/AndroidManifest.xml.

For Android 10+ background tracking, the user must grant background location. For Android 13+, notification permission is also required for the foreground service notification. requestPermission() asks for foreground location, notification permission where applicable, and background location when needed.

If you send locations to a local http:// backend during development, allow cleartext traffic in your app manifest or use HTTPS:

<application
  android:usesCleartextTraffic="true">
  ...
</application>

Usage

import {
  configure,
  requestPermission,
  startTracking,
  stopTracking,
  sync,
} from 'react-native-gps-tracker';

configure({
  android: {
    intervalMs: 3000,
    distanceFilterMeters: 0,
    providers: ['gps', 'network'],
    writeLastKnownLocationOnStart: true,
  },
  ios: {
    distanceFilterMeters: 10,
    stationaryRadiusMeters: 150,
  },
  actions: [
    {
      type: 'http',
      url: 'https://example.com/api/locations',
      method: 'POST',
      headers: {
        Authorization: 'Bearer token',
        'Content-Type': 'application/json',
      },
      body: {
        latitude: '$latitude',
        longitude: '$longitude',
        accuracy: '$accuracy',
        timestamp: '$timestamp',
      },
    },
  ],
});

requestPermission();
startTracking();

// Optional.
stopTracking();

Batched HTTP uploads

HTTP actions support batching with option names similar to react-native-background-geolocation: autoSync, autoSyncThreshold, batchSync, and maxBatchSize.

configure({
  actions: [
    {
      type: 'http',
      url: 'https://example.com/api/locations/batch',
      method: 'POST',
      batchSync: true,
      autoSync: true,
      autoSyncThreshold: 10,
      maxBatchSize: 50,
      body: {
        latitude: '$latitude',
        longitude: '$longitude',
        accuracy: '$accuracy',
        speed: '$speed',
        course: '$course',
        timestamp: '$timestamp',
      },
      batchBody: {
        locations: '$locations',
      },
    },
  ],
});
  • batchSync: true: stores each rendered location body in a native queue instead of uploading immediately.
  • autoSync: true: automatically flushes the queue. Defaults to true.
  • autoSyncThreshold: fallback minimum queued records before auto sync when maxBatchSize is not set.
  • maxBatchSize: number of queued records required before native sends one batch request. After a successful response, only that uploaded batch is removed from the native queue.
  • batchBody: optional wrapper for the batch request body. Use $locations where the queued array should be injected. If omitted, the request body is the raw locations array.

If autoSync is false, locations are only queued until you call:

sync();

On iOS, the batched HTTP queue is persisted in SQLite at the native layer. On Android, it is persisted with Room. Successful HTTP responses in the 2xx range remove only the uploaded rows; failed requests keep their rows for the next automatic or manual sync.

Contributing

License

MIT


Made with create-react-native-library