> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-docs-limits-personalize.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Location Triggered

> Set up geofence-based location-triggered push notifications in your Android app with the MoEngage SDK.

# Prerequisites

To use location triggered (Geofence) push, your app must request the following:

* ACCESS\_FINE\_LOCATION
* ACCESS\_BACKGROUND\_LOCATION if your app targets Android 10 (API level 29) or later.

<Info>
  For location triggered push to work, ensure your Application has the following enabled: Location permission, Play Services location library, and device's location.
</Info>

For more information, refer to [Android Request Geofences](https://developer.android.com/training/location/geofencing#RequestGeofences).

# SDK Installation

## Installing using BOM

Integration using BOM  is the recommended way of integration; refer to the [Install Using BOM](https://www.moengage.com/docs/developer-guide/android-sdk/sdk-integration/basic-integration/Install-Using-BOM) document. Once you have configured the BOM add the dependency in the *app/build.gradle* file as shown below

<CodeGroup>
  ```Groovy build.gradle wrap theme={null}
  dependencies {
      ...
      implementation("com.moengage:geofence")
  }
  ```
</CodeGroup>

Once the BOM is configured, include the specific MoEngage modules required for the application. \
Note: Version numbers are not required for these dependencies; the BOM automatically manages them.

# Configure Geofence

By default, the geofence feature is not enabled. To enable the feature, call the below API.

<CodeGroup>
  ```kotlin Kotlin wrap theme={null}
  MoEGeofenceHelper.getInstance().startGeofenceMonitoring(context)
  ```

  ```java Java theme={null}
  MoEGeofenceHelper.getInstance().startGeofenceMonitoring(context);
  ```
</CodeGroup>

At any time if you want to stop the geofence monitoring or feature, use the below API. This API will remove the existing geofences.

<CodeGroup>
  ```kotlin Kotlin wrap theme={null}
  MoEGeofenceHelper.getInstance().stopGeofenceMonitoring(context)
  ```

  ```java Java theme={null}
  MoEGeofenceHelper.getInstance().stopGeofenceMonitoring(context);
  ```
</CodeGroup>

## Callback

The MoEngage SDK can notify your application whenever a geofence is triggered. If the listener returns `true`, your application consumes the trigger and the SDK doesn't process it further. Returning `false` lets the SDK process the trigger as usual, so the listener can be used purely for logging or analytics.

Implement [`OnGeofenceHitListener`](https://moengage.github.io/android-api-reference/geofence/com.moengage.geofence.listener/-on-geofence-hit-listener/index.html) and register it in your Application class `onCreate()` using [`MoEGeofenceHelper.getInstance().addListener()`](https://moengage.github.io/android-api-reference/geofence/com.moengage.geofence/-mo-e-geofence-helper/add-listener.html).

<CodeGroup>
  ```kotlin Kotlin wrap theme={null}
  class MyApplication : Application() {
      override fun onCreate() {
          super.onCreate()

          MoEGeofenceHelper.getInstance().addListener(OnGeofenceHitListener { geofenceData ->
              // Log or analytics for the triggered geofence.
              // Return true to consume the trigger; false lets the SDK process it.
              false
          })
      }
  }
  ```

  ```java Java theme={null}
  public class MyApplication extends Application {
      @Override
      public void onCreate() {
          super.onCreate();

          MoEGeofenceHelper.getInstance().addListener(geofenceData -> {
              // Log or analytics for the triggered geofence.
              // Return true to consume the trigger; false lets the SDK process it.
              return false;
          });
      }
  }
  ```
</CodeGroup>
