Geofencing Blog For App Developers

How to monitor more than 20 regions in your IOS app

The region monitoring feature of IOS only provides the possibility to monitor up to 20 regions at a time. If you have more than 20 geofences, then you have to manage these geofences yourself. You have to ensure that the 20 geofences your user is closest to are the 20 active monitored regions.

iOS provides significant location changes that inform your app that the user has made a significant movement. What is significant isn’t formally defined, but it should be enough to replace the existing geofences with the 20 nearest ones. You can calculate the distance to each geofence by using the Haversine formula. Because these significant location changes sometimes occur multiple times within a short period of time, you shouldn’t perform heavy or long running tasks (such as HTTP-requests) every time an update occurs.

You can subscribe to significant location changes just like you subscribe to normal location updates. An important difference between normal location updates and significant location updates is that the significant location updates continue, even when your app is no longer running. When a significant location change occurs when your app is no longer running, your app will be started in the background and you receive the location update directly when you start listening for significant location updates.

Here is a code snippet that shows how to listen to significant location changes:

@interface SLCListener : NSObject<CLLocationManagerDelegate> {
    CLLocationManager* locationManager;

@implementation SLCListener

-(id)init {
    if ((self = [super init])) {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;

        [locationManager startMonitoringSignificantLocationChanges];
    return self;

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
//update your geofences here


In the didUpdateLocations: method you receive an array with locations where iOS thinks you currently are. You can compare these locations based on accuracy and age to determine the best one.

To start the monitoring of a region you call the method [locationManager startMonitoringForRegion:region]. These regions stay active when your app is closed and even when the device is restarted. Therefore you always have to check what fences are active before you start monitoring for new regions. You can get the currently active geofences with the call locationManager.monitoredRegions. That call returns a set with CLRegion objects. Each region has a radius and a center coordinate which you can use to determine whether the geofence is still relevant. When it is no longer relevant, you can tell iOS with the method [locationManager stopMonitoringForRegion:region].


Manage geofences in our dashboard
Manage geofences in our dashboard

If you don’t want the hassle to deal with these problems and just send location based notifications, then you can integrate Plot. We have spent a lot of time in ensuring you get a convenient to use library, high accuracy geofences, while using almost no battery of the device we are running on. We also provide a dashboard where you can enter these notifications and see how well they perform. You don’t have to write code to get these notifications on your device, our library takes care of that. Sign up for a free account now!

Don’t want to think about this? Start geofencing right now without a hassle!

I want to  Learn More About Plot Plugin  first, OR I want to Sign Up  straight away!

Geofencing Developer ios

Subscribe to Email Updates