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

# 位置情報トリガー

> MoEngage SDK を使用して、Android アプリでジオフェンスベースの位置情報トリガーのプッシュ通知を設定します。

# 前提条件

位置情報トリガー（Geofence）のプッシュを使用するには、アプリで以下をリクエストする必要があります。

* ACCESS\_FINE\_LOCATION
* ACCESS\_BACKGROUND\_LOCATION（アプリが Android 10（API レベル 29）以降をターゲットとする場合）

> [!NOTE]
>
> 位置情報トリガーのプッシュが機能するように、アプリケーションで位置情報の権限、Play Services の位置情報ライブラリ、デバイスの位置情報が有効になっていることを確認してください。

詳細については、[Android Request Geofences](https://developer.android.com/training/location/geofencing#RequestGeofences) を参照してください。

# SDK のインストール

## BOM を使用したインストール

BOM を使用した連携が推奨される連携方法です。[BOM を使用したインストール](https://www.moengage.com/docs/developer-guide/android-sdk/sdk-integration/basic-integration/Install-Using-BOM)のドキュメントを参照してください。BOM を設定したら、以下のように *app/build.gradle* ファイルに依存関係を追加します。

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

BOM を設定したら、アプリケーションに必要な特定の MoEngage モジュールを含めます。\
注: これらの依存関係にバージョン番号は必要ありません。BOM によって自動的に管理されます。

# Geofence の設定

デフォルトでは、ジオフェンス機能は有効になっていません。この機能を有効にするには、以下の API を呼び出します。

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

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

ジオフェンスの監視または機能を停止したい場合は、いつでも以下の API を使用できます。この API は既存のジオフェンスを削除します。

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

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

## コールバック

MoEngage SDK は、ジオフェンスがトリガーされるたびにアプリケーションに通知できます。リスナーが `true` を返すと、アプリケーションがトリガーを処理し、SDK はそれ以上処理しません。`false` を返すと SDK が通常どおりトリガーを処理するため、リスナーをログ記録や分析のためだけに使用できます。

[`OnGeofenceHitListener`](https://moengage.github.io/android-api-reference/geofence/com.moengage.geofence.listener/-on-geofence-hit-listener/index.html) を実装し、Application クラスの `onCreate()` で [`MoEGeofenceHelper.getInstance().addListener()`](https://moengage.github.io/android-api-reference/geofence/com.moengage.geofence/-mo-e-geofence-helper/add-listener.html) を使用して登録します。

```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;
        });
    }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.