06 – Listen to geofence entries & exits

Implementation #

Please note! All the code snippets in this section have been provided for Android. If you use iOS, you’ll find it easy to translate them appropriately.

You may want to be aware of users entering and leaving the geofences of your building. In order to listen to these interactions you must implement the GeofenceListener interface / delegate (Android, iOS). With this interface you will be notified with a list of Geofences(Android, iOS) when the user enters or leaves any of them:

private GeofenceListener geofenceListener = new GeofenceListener() {

    @Override
    public void onEnteredGeofences(List<Geofence> enteredGeofences) {
        Log.d(TAG, "onEnteredGeofences: ");
    }

    @Override
    public void onExitedGeofences(List<Geofence> exitedGeofences) {
        Log.d(TAG, "onExitedGeofences: ");
    }

};

In order to start using this listener you must attach it to our SDK with the following line of code:

// Make sure you have initialized our SDK with SitumSdk.init(Context)
SitumSdk.locationManager().setGeofenceListener(geofenceListener);

In case you want to stop this listener, do the following:

SitumSdk.locationManager().setGeofenceListener(null);

Remember to set this listener before the user starts positioning, it won’t work if you attach it while positioning.

Take in cosideration #

  • This listener will only work with SDK 2.80.0 onwards.
  • Positioning geofences (with trainer_metadata custom field) will be ignored by these callbacks. As this type of geofences are used to get better positioning in uncalibrated areas, the entries and exits inside them won’t be notified.
  • These callbacks only work with indoor locations. Any outdoor location will produce a call to onExitedGeofences with the last positioned geofences list as parameter.

Subscribe to our newsletter

BASIC INFORMATION ON DATA PROTECTION

Data controller: SITUM TECHNOLOGIES, S.L.
Contact: Data controller: situm@situm.es
Responsible for protection: dpo@situm.es
Purpose and legal basis: To manage the sending of SITUM newsletters only with consent.
Legitimation: Express consent of the interested party.
Recipients: The data will not be passed on to third parties with the exception of legal obligations.
Retention period: As long as the interested party remains subscribed to the newsletter (a link to unsubscribe will be available in each newsletter sent by Situm).
Rights: The interested party may at any time revoke their consent, as well as exercise their rights of opposition, access, conservation, rectification, limitation, deletion of data and not be subject to a decision based only on automated data processing, by writing to SITUM at the addresses indicated.
Additional Information: You can consult additional and detailed information on Data Protection in our privacy policy.

Please, download your copy here

Thank you for downloading our whitepaper. Please do not hesitate to contact us if you would like to know more about how our solutions can help your business. Download whitepaper


Close window