Installation and quick start
This page takes you from an empty React Native project to location points arriving on a backend. Expect about 15 minutes.
Requirements
| Requirement | Version |
|---|---|
| React Native | New Architecture enabled (TurboModules). Tested on 0.88. |
| Android | minSdkVersion 24 or higher, compileSdkVersion 36 recommended, Java 17 |
| iOS | iOS 15.1 or higher, CocoaPods |
| Build type | Debug for the Evaluation edition. Release builds need a license. |
The package is a TurboModule. If your app still runs the old architecture, enable the New Architecture first (newArchEnabled=true in android/gradle.properties, and RCT_NEW_ARCH_ENABLED=1 when running pod install on older React Native versions).
1. Install
npm install react-native-background-location-pro-eval
# or
yarn add react-native-background-location-pro-eval
Then install the iOS pods:
cd ios && pod install && cd ..
Autolinking registers the module on both platforms. You do not need to edit MainApplication, AppDelegate, or register any package by hand.
2. Add the platform configuration
Each platform needs a few permission and background entries before tracking can work:
- Android setup: most permissions merge automatically; you only handle runtime prompts and, optionally, cleartext HTTP for local testing.
- iOS setup: add
UIBackgroundModes,BGTaskSchedulerPermittedIdentifiersand the usage strings toInfo.plist.
3. Run a backend that accepts points
The tracker sends batches with POST {serverUrl}/api/location/track. For a first test, this 20-line Node server is enough:
const http = require('http');
http
.createServer((req, res) => {
if (req.method === 'POST' && req.url === '/api/location/track') {
let body = '';
req.on('data', chunk => (body += chunk));
req.on('end', () => {
const batch = JSON.parse(body);
console.log(`batch ${batch.batchId}: ${batch.points.length} points`);
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify({ok: true}));
});
return;
}
res.writeHead(404);
res.end();
})
.listen(3000, () => console.log('listening on :3000'));
node server.js
The full request format is in Offline tracking and sync.
- Android emulator: use
http://10.0.2.2:3000. - iOS simulator: use
http://localhost:3000. - Physical device: use your computer's LAN IP (for example
http://192.168.1.20:3000), or a tunnel such as ngrok for HTTPS.
Plain http:// URLs need the cleartext exceptions described in the platform setup pages.
4. Start tracking with hooks
Most apps only need the three React hooks. They own permission prompts, start/stop/sync, status, and the latest points. Prefer this path unless you need direct handlers.
import React from 'react';
import {Button, SafeAreaView, Text} from 'react-native';
import {
useLocationTracking,
useLocationUpdates,
usePermissions,
} from 'react-native-background-location-pro-eval';
const SERVER_URL = 'http://10.0.2.2:3000'; // see the tip above
export default function App() {
const permissions = usePermissions();
const {isTracking, status, startTracking, stopTracking} = useLocationTracking({
serverUrl: SERVER_URL,
});
const {latestLocation} = useLocationUpdates();
return (
<SafeAreaView style={{padding: 24, gap: 12}}>
<Text>{permissions.guidance.message}</Text>
{permissions.guidance.code !== 'ok' && (
<Button
title="1. Grant location permission"
onPress={() =>
permissions.hasForeground
? permissions.requestAlways()
: permissions.requestWhenInUse()
}
/>
)}
<Button
title={isTracking ? 'Stop tracking' : '2. Start tracking'}
onPress={() => (isTracking ? stopTracking() : startTracking())}
/>
<Text>
Last point:{' '}
{latestLocation
? `${latestLocation.latitude.toFixed(5)}, ${latestLocation.longitude.toFixed(5)}`
: 'none yet'}
</Text>
<Text>
Pending: {status.pending} · Synced: {status.synced}
</Text>
<Text>Status: {status.message}</Text>
</SafeAreaView>
);
}
Need HTTP headers, geofences, a weekly schedule, or your own store? Call the same LocationTracker API. How much control you take is up to you. See the full paste-ready screen in React hooks.
5. Verify
- Follow the permission guidance and accept the prompts (Always is required for killed-app tracking).
- Tap Start tracking.
- Walk around, or simulate a route (Android emulator: Extended controls > Location > Routes; iOS simulator: Features > Location > City Run).
- Your server logs
batch ...: N points, and the app showsSyncedincreasing. - Background the app, or swipe it away. Points keep arriving.
If nothing arrives, read status from the hook (or call LocationTracker.getStatus()) and check the troubleshooting guide. In particular, check that buildTier is 'debug'.
Next steps
- React hooks: paste-ready screen and helper APIs.
- Tracking lifecycle: start, stop and recovery behavior.
- Examples: maps, sync badges, and production config.
- API reference: every method when you want more control.
- Tune battery use with tracking profiles.