We're excited to introduce a React Native module for Radar with support for iOS and Android.
React Native is a framework from Facebook that lets you build mobile apps using only JavaScript. It abstracts away cross-platform differences, much like Radar abstracts away cross-platform differences between location services on iOS and Android.
Now it's easier than ever to add location tracking and context to your React Native apps. After you sign up for Radar, create geofences, and configure your projects, you can start tracking users and receiving events with just a few lines of code:
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import Radar from 'react-native-radar';
export default class MyComponent extends Component {
componentDidMount() {
// identify the user and request permissions
Radar.setUserId(this.state.userId);
Radar.requestPermissions(true);
// track the user's location once in the foreground
Radar.trackOnce().then((result) => {
// do something with result.events, result.user.geofences
}).catch((err) => {
// optionally, do something with err
});
// start tracking the user's location in the background
Radar.startTracking();
}
}
// receive events
Radar.on('events', (result) => {
// do something with result.events, result.user
});
// receive location updates
Radar.on('location', (result) => {
// do something with result.location, result.user
});
// receive errors
Radar.on('error', (err) => {
// do something with err
});
Check out the react-native-radar repo on GitHub and the react-native-radar package on npm to get started.
Happy coding!
See what Radar’s location and geofencingsolutions can do for your business.