What's geofencing?

06.19.2014

Geofencing is a technical word for a quite simple concept: it’s all about setting virtual areas and monitoring a smartphone entry and exit of these areas. The main interest is to allow a developer to fire notifications (based on geolocation) even in the background or when the app isn’t running. On iOS, if your app was not active, it can be awakened for a few seconds to handle the geofencing event. The goal of this article is to summarize basic knowledge on the subject, through the eyes of an app maker.

Geofencing in iOS and Android

In its developer documentation, Apple communicates on the terms “regions” and “region monitoring”. It has been available since iOS 4.0 and has been improved.

On Android, geofencing is quite recent (May 2013): it is an addition to Locations Services in Google Play services APK. It gives the developer an abstraction layer and therefore avoid managing various complex cases.

Both implementations define a circle around a point. If you need to define more complex areas, you will have to take a look at third party solutions.
Here is a list of a few things to know about region monitoring / geofencing in iOS and Android:

iOS’s region monitoring Android’s geofencing
Availability Since iOS 4.0 Since 1.6, Location Services required
Background execution Yes Yes
Number limit of monitored geofences for an app 20 Illimited
Possibility to set an expiration duration No Yes
Testing In Simulator or on a device Using Mock mode

With a little imagination, geofencing can bring cool features to your app. Here are a few examples:

  • In a news app: to refresh content before taking the metro
  • In a calendar app: to remind you to collect your clothes at the dry cleaner
  • For a settings changer app: when leaving home, “on the go” features can be enabled
  • In an ambient location social network app: to have an idea of where your close friends are.

Some apps use it cleverly:

  • Instapaper, a news reader (e.g. refresh your news feed when leaving home)
  • IFTTT, a service that lets you connect an action to a trigger (e.g. unmute your phone when you get home)

Accuracy and battery consumption

This part will discuss the compromise between good accuracy and battery life. GPS is very battery consuming. Thus in order to save battery life, geofencing does not rely on it. Instead, it uses cell tower information and Wi-Fi which provide a quite fair accuracy (if available!) and are less energy intensive. It’s all about the compromise between good accuracy and battery life.

Accuracy

Yes, cell tower and Wi-Fi help your smartphone to locate itself. How? It uses triangulation and relies on the locations data Apple / Google collect. Accuracy highly depends on density of Wi-Fi routers or cell towers: triangulation typically works poorly in rural environment.

To give you an idea of the range of accuracy, Google provides the following indications:

Type Accuracy Notes
GPS “several meters” (5-15m) does not work indoor
Wi-Fi “similar to the access range of a typical router” (20-200m) fair accuracy
Cell ID “distances up to several thousand meters” (500m-10km) depending on antennae density

Therefore, you should not use geofencing with iOS and Android SDKs and expect having a very accurate location. iOS’s implementation added a threshold (which is not documented for Android but it may be the case as well) to prevent spurious notifications:

The user’s location must cross the region boundary, move away from the boundary
by a minimum distance, and remain at that minimum distance for
at least 20 seconds before the notifications are reported.
The specific threshold distances are determined by the hardware and the location technologies
that are currently available. For example, if Wi-Fi is disabled, region monitoring is
significantly less accurate. However, for testing purposes, you can assume that
the minimum distance is approximately 200 meters.

Thus the questions you should ask yourself when designing your app are:

  • Do my users live in town? (dense Wi-Fi routers and cell towers coverage)
  • Do my users let the Wi-Fi running when they use my app? (some may deactivate it when outside, thus decreasing accuracy of location)
  • Do I need the notification to be triggered immediately after the user crosses the geofence?
  • Is the worst case accuracy acceptable for my service? (potentially very poor in a rural environment)

Battery usage

Since geofencing only uses cellular network and Wi-Fi capacities, it should not be really battery consuming. However, users of iOS’s built-in region monitoring in “Reminders” complained about an abnormally short battery life. Geofencing’s impact on battery life will be further discussed in our next article on the topic.

Google introduced hardware geofencing with Jelly Bean, which is more power efficient than performing location computation in software. It is available on Nexus 4 and 7 (2013) and maybe others but neither Google nor OEMs communicated on it after Jelly Bean’s release.

They also added a Wi-Fi scan-only mode (software), which is exactly the same as in iOS.

Wrap-up

Geofencing may help you add discrete but awesome features to your app when the use case is well-suited (i.e. if the accuracy suits your needs). You will have to test battery drain but if it turns out that it is acceptable, nothing should prevent you from using it!

Both Apple and Google provide developers with quite high-level methods to use geofencing in your apps. To make it reasonably battery consuming, it uses Wi-Fi and/or cell tower triangulation. The drawback of that technique is that it has a limited accuracy and highly depends on the density of transmitters but it can be sufficient to your use cases.

On Android, you can wake up your app with geofencing and then retrieve a GPS fix to improve the accuracy of the location. But if you cannot rely on geofencing because of its coarse precision, you will have to look for another solution. You may have heard of iBeacon, which can help on indoor location but this will be for another post.