Skip to content

jingjing2222/react-native-nitro-geolocation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

71 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

react-native-nitro-geolocation

NPM

Simple and Modern Geolocation for React Native β€” Powered by Nitro Modules with JSI

A complete reimplementation of @react-native-community/geolocation for the React Native New Architecture, featuring:

  • 🎯 Simple functional API β€” Direct function calls, no complex abstractions
  • ⚑ JSI-powered performance β€” Direct native calls without the Bridge
  • πŸ” 100% API compatibility via /compat for easy migration
  • 🧹 Automatic cleanup β€” No manual subscription management
  • πŸ“± Consistent behavior across iOS and Android
  • πŸ› οΈ DevTools Plugin β€” Mock locations with interactive map (Rozenite)

react-native-nitro-geolocation


πŸ“˜ Documentation

Full documentation available at: πŸ‘‰ https://react-native-nitro-geolocation.pages.dev


🧭 Introduction

React Native Nitro Geolocation provides two APIs to fit your needs:

1. Modern API (Recommended)

Simple functional API with direct calls and a single hook for tracking:

import {
  setConfiguration,
  requestPermission,
  getCurrentPosition,
  useWatchPosition,
} from "react-native-nitro-geolocation";

// Configure once at app startup
setConfiguration({
  authorizationLevel: "whenInUse",
  locationProvider: "auto",
});

// Request permission
const status = await requestPermission();

// Get current location
const position = await getCurrentPosition({
  enableHighAccuracy: true,
});

// Continuous tracking with hook
function LocationTracker() {
  const { position, error, isWatching } = useWatchPosition({
    enabled: true,
    enableHighAccuracy: true,
    distanceFilter: 10,
  });

  if (error) return <Text>Error: {error.message}</Text>;
  if (!position) return <Text>Waiting...</Text>;

  return (
    <Text>
      {position.coords.latitude}, {position.coords.longitude}
    </Text>
  );
}

Benefits:

2. Legacy API (Compatibility)

Drop-in replacement for @react-native-community/geolocation:

import Geolocation from "react-native-nitro-geolocation/compat";

Geolocation.getCurrentPosition(
  (position) => console.log(position),
  (error) => console.error(error),
  { enableHighAccuracy: true }
);

const watchId = Geolocation.watchPosition((position) => console.log(position));
Geolocation.clearWatch(watchId);

⚑ Quick Start

1. Installation

# Install Nitro core and Geolocation module
yarn add react-native-nitro-modules react-native-nitro-geolocation

# or using npm
npm install react-native-nitro-modules react-native-nitro-geolocation

Rebuild your native app:

cd ios && pod install

2. iOS Setup

Add permissions to your Info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires access to your location while it's in use.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app requires access to your location at all times.</string>

3. Android Setup

Add permissions to AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Optional (for background):

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

4. Development Tools (Optional)

DevTools Plugin (Rozenite)

Prerequisites: Requires Rozenite DevTools to be installed.

API Compatibility: Only works with the Modern API. Does not support the Legacy API (/compat).

Mock geolocation data during development with an interactive map interface:

DevTools Plugin

npm install @react-native-nitro-geolocation/rozenite-plugin
# or
yarn add @react-native-nitro-geolocation/rozenite-plugin

Setup:

import {
  useGeolocationDevTools,
  createPosition,
} from "@react-native-nitro-geolocation/rozenite-plugin";

function App() {
  // Enable location mocking in development
  useGeolocationDevTools({
    initialPosition: createPosition("Seoul, South Korea"),
  });

  return <YourApp />;
}

Features:

  • πŸ—ΊοΈ Interactive Leaflet map interface
  • πŸ“ Click to set location instantly
  • ⌨️ Arrow key navigation for precise control
  • πŸ™οΈ 20 pre-configured city presets
  • ✏️ Manual latitude/longitude input
  • πŸ“Š Real-time heading, speed, and accuracy calculation
  • πŸŒ“ Dark mode support

See full DevTools guide β†’


5. Usage

Modern API (Recommended)

// Get current location
const position = await getCurrentPosition({ enableHighAccuracy: true });

// Real-time tracking with hook
const { position, error } = useWatchPosition({
  enabled: true,
  distanceFilter: 10
});

Legacy API (Compatibility)

import Geolocation from "react-native-nitro-geolocation/compat";

Geolocation.getCurrentPosition((pos) => console.log(pos));
const watchId = Geolocation.watchPosition((pos) => console.log(pos));
Geolocation.clearWatch(watchId);


πŸ”„ Migration from @react-native-community/geolocation

Change the import to use /compat β€” 100% API compatible:

- import Geolocation from '@react-native-community/geolocation';
+ import Geolocation from 'react-native-nitro-geolocation/compat';

πŸ“– Learn More


License

Unlicense β€” This project is released into the public domain.

About

A React Native Geolocation module Using Nitro

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors