Implementation #
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.