> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/android/ja/navigation/v2/llms.txt)

# Arrival detection

In turn-by-turn applications using the Mapbox Navigation SDK, the SDK detects when a user arrives at a waypoint or a final destination and allows you create an arrival experience. There are few ways you can implement the experience with Navigation SDK or customize it based on your requirements.

## Listen for arrival events

The [`ArrivalObserver`](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-core/com.mapbox.navigation.core.arrival/-arrival-observer/) interface is a callback, which can be used to receive the following events:

-   **`onWaypointArrival`** is triggered when [RouteProgress.currentState](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.trip.model/-route-progress/current-state.html) is equal to [RouteProgressState.COMPLETE](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.trip.model/-route-progress-state/-c-o-m-p-l-e-t-e/). The event is triggered once per route leg, when there are multiple legs to navigate. If we are on the last leg of the route `onFinalDestinationArrival` is triggered instead.
-   **`onNextRouteLegStart`** is triggered once the driver has arrived at a stop and has started navigating the next leg.
-   **`onFinalDestinationArrival`** is triggered when [RouteProgress.currentState](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.trip.model/-route-progress/current-state.html) is equal to [RouteProgressState.COMPLETE](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-base/com.mapbox.navigation.base.trip.model/-route-progress-state/-c-o-m-p-l-e-t-e/). The event is triggered once when there are no more route legs to navigate.

### Create an instance of `ArrivalObserver`

Instantiate `ArrivalObserver` in your `Activity` or `Fragment`.

```kotlin
val arrivalObserver = object : ArrivalObserver() {

  override fun onWaypointArrival(routeProgress: RouteProgress) {
    // do something when the user arrives at a waypoint
  }

  override fun onNextRouteLegStart(routeLegProgress: RouteLegProgress) {
    // do something when the user starts a new leg
  }

  override fun onFinalDestinationArrival(routeProgress: RouteProgress) {
    // do something when the user reaches the final destination
  }
}
```

### Start and stop receiving arrival events

Register and unregister the `ArrivalObserver` interface with [your already-instantiated `MapboxNavigation` object](https://docs.mapbox.com/android/ja/navigation/v2/guides/get-started/initialization/#create-the-mapboxnavigation-object) at appropriate places.

```kotlin
override fun onStart() {
  super.onStart()
  mapboxNavigation.registerArrivalObserver(arrivalObserver)
}

override fun onStop() {
  super.onStop()
  mapboxNavigation.unregisterArrivalObserver(arrivalObserver)
}
```

## Customize arrival events

The Mapbox Navigation SDK allows you to customize when to trigger the `onNextRouteLegStart` event when navigating waypoints with multiple legs. You can customize the experience by implementing [`ArrivalController`](https://docs.mapbox.com/android/navigation/v2/api/2.22.2/libnavigation-core/com.mapbox.navigation.core.arrival/-arrival-controller/).

The Mapbox Navigation SDK includes a default implementation of `ArrivalController` known as `AutoArrivalController` and will automatically decide when to trigger `onNextRouteLegStart` event.

To use your custom controller, create a new `ArrivalController`.

```kotlin
val myArrivalController = object : ArrivalController() {

  override fun navigateNextRouteLeg(routeLegProgress: RouteLegProgress): Boolean {

  }
}
```

You can then pass your controller to [your already-instantiated `MapboxNavigation` object](https://docs.mapbox.com/android/ja/navigation/v2/guides/get-started/initialization/#create-the-mapboxnavigation-object).

```kotlin
mapboxNavigation.setArrivalController(myArrivalController)
```

When your controller `navigateNextRouteLeg` returns `true`, the navigator will start navigating to the next stop by triggering [arrivalObserver.onNextRouteLegStart](#listen-for-arrival-events). When your controller `navigateNextRouteLeg` returns `false` the navigator will not start navigating to the next stop.

If in any situation your controller `navigateNextRouteLeg` returns false always, you can force trigger `navigateNextRouteLeg` to continue navigation.

```kotlin
mapboxNavigation.navigateNextRouteLeg()
```