libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/offroute/OffRouteDetector.java
@Override
  public boolean isUserOffRoute(Location location, RouteProgress routeProgress, MapboxNavigationOptions options,
                                RingBuffer<Integer> distancesAwayFromManeuver, OffRouteCallback callback) {

    if (!validOffRoute(location, options)) {
      return false;
    }

    Point currentPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());

    // Get distance from the current step to future point
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    double distanceFromCurrentStep = userTrueDistanceFromStep(currentPoint, currentStep);

    // Create off-route radius from the max of our dynamic or accuracy based tolerances
    double offRouteRadius = createOffRouteRadius(location, routeProgress, options, currentPoint);

    // Off route if this distance is greater than our offRouteRadius
    boolean isOffRoute = distanceFromCurrentStep > offRouteRadius;

    // If not offRoute at this point, do not continue with remaining logic
    if (!isOffRoute) {
      // Even though the current point is not considered off-route, check to see if the user is
      // moving away from the maneuver.
      return isMovingAwayFromManeuver(location, routeProgress, distancesAwayFromManeuver, currentPoint);
    }

    // If the user is considered off-route at this point, but they are close to the upcoming step,
    // do not send an off-route event and increment the step index to the upcoming step
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (closeToUpcomingStep(options, callback, currentPoint, upComingStep)) {
      return false;
    }

    // All checks have run, return true
    updateLastReroutePoint(location);
    return true;
  }
/**
   * Method in charge of running a series of test based on the device current location
   * and the user progress along the route.
   * <p>
   * Test #1:
   * Valid or invalid off-route.  An off-route check can only continue if the device has received
   * at least 1 location update (for comparison) and the user has traveled passed
   * the {@link MapboxNavigationOptions#minimumDistanceBeforeRerouting()} checked against the last re-route location.
   * <p>
   * Test #2:
   * Distance from the step. This test is checked against the max of the dynamic rerouting tolerance or the
   * accuracy based tolerance. If this test passes, this method then also checks if there have been &gt;= 3
   * location updates moving away from the maneuver point. If false, this method will return false early.
   * <p>
   * Test #3:
   * Checks if the user is close the upcoming step.  At this point, the user is considered off-route.
   * But, if the location update is within the {@link MapboxNavigationOptions#maneuverZoneRadius()} of the
   * upcoming step, this method will return false as well as send fire {@link OffRouteCallback#onShouldIncreaseIndex()}
   * to let the <tt>NavigationEngine</tt> know that the
   * step index should be increased on the next location update.
   *
   * @return true if the users off-route, else false.
   * @since 0.2.0
   */
Method in charge of running a series of test based on the device current location
and the user progress along the route.

Test #1:
Valid or invalid off-route.  An off-route check can only continue if the device has received
at least 1 location update (for comparison) and the user has traveled passed
the  MapboxNavigationOptions#minimumDistanceBeforeRerouting() checked against the last re-route location.

Test #2:
Distance from the step. This test is checked against the max of the dynamic rerouting tolerance or the
accuracy based tolerance. If this test passes, this method then also checks if there have been >= 3
location updates moving away from the maneuver point. If false, this method will return false early.

Test #3:
Checks if the user is close the upcoming step.  At this point, the user is considered off-route.
But, if the location update is within the  MapboxNavigationOptions#maneuverZoneRadius() of the
upcoming step, this method will return false as well as send fire  OffRouteCallback#onShouldIncreaseIndex()
to let the NavigationEngine know that the
step index should be increased on the next location update.

@return true if the users off-route, else false.
Method in charge of running a series of test based on the device current location and the user progress along the route . Test #1 : Valid or invalid off - route . An off - route check can only continue if the device has received at least 1 location update ( for comparison ) and the user has traveled passed the MapboxNavigationOptions#minimumDistanceBeforeRerouting () checked against the last re - route location . Test #2 : Distance from the step . This test is checked against the max of the dynamic rerouting tolerance or the accuracy based tolerance . If this test passes this method then also checks if there have been > = 3 location updates moving away from the maneuver point . If false this method will return false early . Test #3 : Checks if the user is close the upcoming step . At this point the user is considered off - route . But if the location update is within the MapboxNavigationOptions#maneuverZoneRadius () of the upcoming step this method will return false as well as send fire OffRouteCallback#onShouldIncreaseIndex () to let the NavigationEngine know that the step index should be increased on the next location update . @return true if the users off - route else false .
@Override
  public boolean isUserOffRoute(Location location, RouteProgress routeProgress, MapboxNavigationOptions options,
                                RingBuffer<Integer> distancesAwayFromManeuver, OffRouteCallback callback) {
    if (!validOffRoute(location, options)) {
      return false;
    }
    Point currentPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    double distanceFromCurrentStep = userTrueDistanceFromStep(currentPoint, currentStep);
    double offRouteRadius = createOffRouteRadius(location, routeProgress, options, currentPoint);
    boolean isOffRoute = distanceFromCurrentStep > offRouteRadius;
    if (!isOffRoute) {
      return isMovingAwayFromManeuver(location, routeProgress, distancesAwayFromManeuver, currentPoint);
    }
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (closeToUpcomingStep(options, callback, currentPoint, upComingStep)) {
      return false;
    }
    updateLastReroutePoint(location);
    return true;
  }
@ Override public boolean isUserOffRoute ( Location location , RouteProgress routeProgress , MapboxNavigationOptions options , RingBuffer < Integer > distancesAwayFromManeuver , OffRouteCallback callback ) { if ( ! validOffRoute ( location , options ) ) { return false ; } Point currentPoint = Point . fromLngLat ( location . getLongitude ( ) , location . getLatitude ( ) ) ; LegStep currentStep = routeProgress . currentLegProgress ( ) . currentStep ( ) ; double distanceFromCurrentStep = userTrueDistanceFromStep ( currentPoint , currentStep ) ; double offRouteRadius = createOffRouteRadius ( location , routeProgress , options , currentPoint ) ; boolean isOffRoute = distanceFromCurrentStep > offRouteRadius ; if ( ! isOffRoute ) { return isMovingAwayFromManeuver ( location , routeProgress , distancesAwayFromManeuver , currentPoint ) ; } LegStep upComingStep = routeProgress . currentLegProgress ( ) . upComingStep ( ) ; if ( closeToUpcomingStep ( options , callback , currentPoint , upComingStep ) ) { return false ; } updateLastReroutePoint ( location ) ; return true ; }
Method in charge of running a series of test based on the device current location
 and the user progress along the route.
Method in charge of running a series of test based on the device current location and the user progress along the route .
// Get distance from the current step to future point // Create off-route radius from the max of our dynamic or accuracy based tolerances // Off route if this distance is greater than our offRouteRadius // If not offRoute at this point, do not continue with remaining logic // Even though the current point is not considered off-route, check to see if the user is // moving away from the maneuver. // If the user is considered off-route at this point, but they are close to the upcoming step, // do not send an off-route event and increment the step index to the upcoming step // All checks have run, return true