Monitor POIs with Geofence

Monitor POIs with Geofence using Android SDK

  1. Create and monitor Geofences
  2. Create regions from Woosmap Search API assets

Create and monitor Geofences

Use region monitoring to determine when the user enters or leaves a geographic region.

Region monitoring (also known as geofencing) combines awareness of the user’s current location with awareness of the user’s proximity to locations that may be of interest. This region is a way for your app to be alerted when the user enters or exits a geographical region. To mark a location of interest, you specify its latitude and longitude. To adjust the proximity for the location, you add a radius. The latitude, longitude, and radius define a Geofence, creating a circular area, or fence, around the location of interest. Find more details about Geofences in the Geofencing documentation

Set up for Geofence monitoring

The first step in requesting Geofence monitoring is to set RegionReadyListener, this should be done as early as possible in your mainActivity on the method onCreate.

protected void onCreate(Bundle savedInstanceState) {

    // [...] //

    this.woosmap.setRegionReadyListener( new WoosRegionReadyListener() );


Woosmap Region Ready Listener

In your mainActivity, create a listener connected to the interface Woosmap.RegionReadyListener and set a callback to retrieve Regions event. This callback is triggered when a region is created.

public class WoosRegionReadyListener implements Woosmap.RegionReadyListener {  
    public void RegionReadyCallback(Region region) { 
            // region data

On the object Region, there are a boolean didEnter that indicate if you are inside or outside of the region based on the system detection. Another boolean isCurrentPositionInside share the same information but based on the position detection (calculated by the SDK and not by the device’s Location Mannager). So you can get didEnter at false and isCurrentPositionInsideat trueif the position is inside the region and the system don’t detect the transition.

By experience, the region enter/exit event from android is triggered on new position inside the region or outside. Indeed the events are not triggered on the crossing limit of the region. So it’s important to have a minimum radius of the region should be set between 100 - 150 meters.

Regions have an associated identifier, which this method uses to look up information related to the region and perform the associated action.

You can recover the regions created in the database of SDK as follows :

Region[] regionList = WoosmapDb.getInstance(mContext, true).getRegionsDAO().getAllRegions();

You can recover all the logs of region event in the database of SDK as follows :

RegionLog[] regionLogList = WoosmapDb.getInstance(mContext, true).getRegionLogsDAO().getAllRegionLogs();

Woosmap RegionLog Ready Listener

In your mainActivity, create a listener connected to the interface Woosmap.RegionLogReadyCallback and set a callback to retrieve Regions Log event. Whenever the user crosses the boundary of one of your app’s registered regions, the system notifies your app and trigger the RegionLogReadyCallback.

public class WoosRegionLogReadyListener implements Woosmap.RegionLogReadyListener {
    public void RegionLogReadyCallback(RegionLog regionLog) {
            // region log event data

Create a custom region

A region is a circular area centered on a geographic coordinate. You can define one using a LatLng object. The radius of the region object defines its boundary. You define the regions you want to monitor and register them with the system by calling the addGeofence(center: LatLng, radius: float radius) method of Woosmap.getInstance(). The system monitors your regions until you explicitly ask it to stop.

Woosmap.getInstance().addGeofence( id, latLng, 100);

The limit of numbers of regions monitored can not been exceed. Indeed, regions are shared resources that rely on specific hardware capabilities. To ensure that all apps can participate in region monitoring, android prevents any single app from monitoring more than 100 regions simultaneously.

To work around this limitation, monitor only regions that are close to the user’s current location. As the user moves, update the list based on the user’s new location.

Be Careful, to have a monitoring regions the user must allow permissions to share the position all time.

Remove regions

To remove all regions created, you can use this method :


To remove a specific region, you can use this method with the id of the region :

Woosmap.getInstance().removeGeofences(String id)

Create regions from Woosmap Search API assets

Set your Private API Key before. See a step-by-step in the Use Search API with Geofencing SDK documentation

Region monitoring is a natural complement to Search requests performed on collected locations. Indeed, Search requests help monitoring the approach to some assets you want to monitor. On every collected location you are aware of the surronding assets (distance to them and even time if using Distance API request). You can then decide to monitor some of those surrounding assets (e.g. the closest ones). Region monitoring is designed to do so.

To create region around the nearest result of the Search API request, enable the tracking properties searchAPICreationRegionEnable. Edit the tracking profile or overload this property to enable this feature:

WoosmapSettings.searchAPICreationRegionEnable = true
Was this article helpful?
Have more questions? Submit a request