Radar is the location platform for mobile apps.
Install the package from npm:
npm install --save react-native-radar
Then, install the native dependencies:
react-native link react-native-radar
If you do not install the native dependencies, you will get an error at run time:
NativeModules.RNRadar is undefined
On iOS, you must add location usage descriptions and background modes to your
Info.plist, then add the SDK to your project, preferably using CocoaPods. Finally, initialize the SDK in
AppDelegate.m, passing in your Radar publishable API key.
On Android, you must add the Google Play Services library to your project, then add the SDK to your project, preferably using Gradle. Finally, initialize the SDK in
MainApplication.java, passing in your Radar publishable API key:
To get a Radar publishable API key, sign up for a Radar account.
First, import the module:
If you are using Places, you must set Facebook as your place data provider.
To set Facebook as your place data provider, call:
To disable Places later, call:
Learn more about Places.
Until you identify the user, Radar will automatically identify the user by device ID.
To identify the user when logged in, call:
userId is a stable unique ID string for the user.
Do not send any PII, like names, email addresses, or publicly available IDs, for
userId. See privacy best practices for more information.
To set an optional dictionary of custom metadata for the user, call:
metadata is a JSON object with up to 16 keys and values of type string, boolean, or number.
Finally, to set an optional description for the user, displayed in the dashboard, call:
description is a string.
You only need to call these functions once, as these settings will be persisted across app sessions.
Before tracking the user's location, the user must have granted location permissions for the app.
To determine the whether user has granted location permissions for the app, call:
status will be a string, one of:
To request location permissions for the app, call:
background is a boolean indicating whether to request background location permissions or foreground location permissions. On Android,
background will be ignored.
Once you have initialized the SDK, you have identified the user, and the user has granted permissions, you can track the user's location.
To track the user's location in the foreground, call:
err will be a string, one of:
ERROR_PUBLISHABLE_KEY: the SDK was not initialized
ERROR_PERMISSIONS: the user has not granted location permissions for the app
ERROR_LOCATION: location services were unavailable, or the location request timed out
ERROR_NETWORK: the network was unavailable, or the network connection timed out
ERROR_UNAUTHORIZED: the publishable API key is invalid
ERROR_SERVER: an internal server error occurred
ERROR_UNKNOWN: an unknown error occurred
Once you have initialized the SDK, you have identified the user, and the user has granted permissions, you can start tracking the user's location in the background.
To start tracking the user's location in the background, call:
Assuming you have configured your project properly, the SDK will wake up while the user is moving (usually every 2-3 minutes), then shut down when the user stops (usually within 3-5 minutes). To save battery, the SDK will not wake up when stopped, and the user must move at least 100 meters from a stop (sometimes more) to wake up the SDK.
To stop tracking the user's location in the background (e.g., when the user logs out), call:
You only need to call these methods once, as these settings will be persisted across app sessions.
To listen for events, location updates, and errors, you can add event listeners:
Add event listeners outside of your component lifecycle (e.g., outside of
componentDidMount) if you want them to work when the app is in the background.
You can also remove event listeners:
For most users, background tracking with the native iOS and Android SDKs uses 1-2% battery per day. Learn more in the in the SDK documentation.
launchOptions for the
You can manually update the user's location by calling:
const location =latitude: 392904longitude: -766122accuracy: 65;Radar;