Check out A Guide to Geofencing in Mobile Applications if you’d like a refresher on how geofencing works!
There are many options when considering geofencing with React Native. Even with so many choices, each has its advantages and limitations. We’ve compiled a list of geofencing libraries for you that will hopefully meet your needs.
Geofences with React Native
Radar – radar.io
Android API 16
* Only offered on Enterprise
** Partially offered free
Radar offers a long list of features – and is definitely the most extensive of the options we’ve compiled.
Radar handles all geofencing and event monitoring server-side rather than on a device. It supports unlimited Circular and Polygonal Geofences with Stop Detection. When Stop Detection is enabled, the library will be able to detect whether the device is moving through a geofence (like driving) or has stopped within the geofence. Entry events will only be triggered if the device stops in the geofence.
Radar can detect when a user visits a place, chain, or category, without having a geofence registered for it. It uses multiple sources in order to gather and supply place data. When enabled, entry and exit events can be monitored. Radar generates an entry event if a user stops at a place matching filters with sufficient confidence, then an exit event when the user leaves the place.
Radar stores and clusters location data for each user. Based on the size, location, and time distribution of clusters, it learns a user’s approximate home and office locations. When enabled, entry and exit events for the user’s home and office can be monitored, as well as started traveling and stopped traveling events.
Radar can detect a user’s country, state, DMA (designated market area), or postal code. When enabled, entry and exit events for a country, state and DMA can be monitored.
Radar supports setting up webhooks and server-side integrations that allow you to send events from Radar to other systems. Webhooks are a free integration that can be used on any license, whereas other integrations require an Enterprise license.
Feature-full dependency that will exceed your needs for geofencing and geolocation monitoring. If your application uses location tracking heavily – whether with just geofences, or with location based insights – then Radar may be a great option for you. Support is also offered on every tier level.
The free-tier provides a great runway for development, but won’t meet the needs of a production-level application. It’s important to note that an Enterprise license is required to access features other than geofencing.
react-native-background-geolocation – transistorsoft.com
Android API 16
This library supports unlimited circular geofences with monitored enter, exit and dwell events. All geofences are stored in an SQLite database which uses geospatial queries to find the closest geofence within a predetermined radius. In other words, if you’ve specified a 10,000 meter proximity radius, it only monitors geofences within that 10,000 meter area.
It uses motion-detection (accelerometer, gyroscope and magnetometer) to detect when the device is moving and when it is stationary. When the device is moving, the plugin will automatically start recording location. When the device is stationary, the plugin will automatically stop recording location to conserve energy.
Android Headless Mode
When enabled on an Android device, this will allow the application to continue responding to events after the application has been terminated. This is particularly useful when you want your application to respond to location events (not just geofences) when the application is closed.
When enabled, it can send HTTPS requests to your server with location and geofence data.
This library definitely has advantages by allowing unlimited geofences and by being battery efficient. Support is included with a license (only required for Android). The higher the license tier, the better the support level, but the Starter level should be sufficient as it provides the same capabilities.
Requires a license for production builds on Android and does not support polygonal geofences.
react-native-boundary – github.com/eddieowens/react-native-boundary
Android API 16
This library is a very basic geofencing library that supports circular geofences.
No license required (Android and iOS).
The typical OS quantity limitations are in place (100 for Android, 20 for iOS). So if you want to support more than that, you will need to handle storing and querying for geofences on your own. This library only monitors enter and exit events.
Supporting Polygonal Geofences
If you decide not to use Radar, which supports polygonal geofences but still need support for them, you can try point-in-polygon. This algorithm takes in a list of points (latitude and longitude) to describe a polygonal shape. Determining if a point is in the polygon requires querying a set of coordinates against the shape.
If none of the React Native libraries we’ve mentioned work for your use case – you can always integrate native geofence handling directly in your React Native application.
Android API 16
This route requires that you write your own native integration for geofencing – which could be an advantage! Only circular geofences are supported.
Because this is natively handled, you’ll have quantity restrictions to work around. If you need to handle more geofences, you’ll need to implement your own database and setup geospatial queries to load/unload geofences from your application.
Natively Supporting Polygonal Geofences
MKPolygon can be used to create polygonal shapes. You can then pass in a location to see if it’s within the polygon.
A point-in-polygon algorithm can be used to see if a location is within a polygonal shape.
|Enter & Exit Alerts||✅||✅||✅||✅|
When choosing a geofencing library, whether by using a React Native dependency or by writing it natively, it’s important to think about what feature support you need. If licensing is a big issue, you have two options: react-native-boundary or write it yourself. Both of these options will provide basic geofencing functionality without additional costs. If licensing isn’t an issue, react-native-background-geolocation is a great option. It provides geofencing features and makes battery-efficiency a high priority, with only a small licensing cost for Android.
Need expert React Native support for your geo-featured application? We’re ready to help!