Java Code Examples for com.mapbox.api.directions.v5.models.DirectionsRoute

The following examples show how to use com.mapbox.api.directions.v5.models.DirectionsRoute. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelper.java    License: MIT License 6 votes vote down vote up
/**
 * This is used when a user has completed a step maneuver and the indices need to be incremented.
 * The main purpose of this class is to determine if an additional leg exist and the step index
 * has met the first legs total size, a leg index needs to occur and step index should be reset.
 * Otherwise, the step index is incremented while the leg index remains the same.
 * <p>
 * Rather than returning an int array, a new instance of Navigation Indices gets returned. This
 * provides type safety and making the code a bit more readable.
 * </p>
 *
 * @param routeProgress   need a routeProgress in order to get the directions route leg list size
 * @param previousIndices used for adjusting the indices
 * @return a {@link NavigationIndices} object which contains the new leg and step indices
 */
static NavigationIndices increaseIndex(RouteProgress routeProgress,
                                       NavigationIndices previousIndices) {
  DirectionsRoute route = routeProgress.directionsRoute();
  int previousStepIndex = previousIndices.stepIndex();
  int previousLegIndex = previousIndices.legIndex();
  int routeLegSize = route.legs().size();
  int legStepSize = route.legs().get(routeProgress.legIndex()).steps().size();

  boolean isOnLastLeg = previousLegIndex == routeLegSize - 1;
  boolean isOnLastStep = previousStepIndex == legStepSize - 1;

  if (isOnLastStep && !isOnLastLeg) {
    return NavigationIndices.create((previousLegIndex + 1), 0);
  }

  if (isOnLastStep) {
    return previousIndices;
  }
  return NavigationIndices.create(previousLegIndex, (previousStepIndex + 1));
}
 
Example #2
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteStepProgressTest.java    License: MIT License 6 votes vote down vote up
@Test
public void distanceRemaining_equalsStepDistanceAtBeginning() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);
  LineString lineString = LineString.fromPolyline(firstLeg.steps().get(5).geometry(), Constants.PRECISION_6);
  double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);

  double stepDistanceRemaining = firstLeg.steps().get(5).distance();
  double legDistanceRemaining = firstLeg.distance();
  double distanceRemaining = route.distance();
  int stepIndex = 4;
  RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, stepIndex, 0);
  RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();

  assertEquals(stepDistance, routeStepProgress.distanceRemaining(), BaseTest.LARGE_DELTA);
}
 
Example #3
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ValidationUtilsTest.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithFalseVoiceInstructions() throws IOException {
  DirectionsRoute route = buildTestDirectionsRoute();
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .voiceInstructions(false)
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #4
Source Project: graphhopper-navigation-android   Author: graphhopper   File: TestRouteBuilder.java    License: MIT License 6 votes vote down vote up
private DirectionsRoute buildRouteWithOptions(DirectionsRoute route) throws IOException {
  List<Point> coordinates = new ArrayList<>();
  RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder()
    .baseUrl(Constants.BASE_API_URL)
    .user("user")
    .profile("profile")
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .geometries("mocked_geometries")
    .voiceInstructions(true)
    .bannerInstructions(true)
    .coordinates(coordinates).build();

  return route.toBuilder()
    .routeOptions(routeOptionsWithoutVoiceInstructions)
    .build();
}
 
Example #5
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteUtilsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void isArrivalEvent_returnsFalseWhenManeuverTypeIsArrival_andIsNotLastInstruction() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  int first = 0;
  RouteLeg routeLeg = route.legs().get(first);
  List<LegStep> routeSteps = routeLeg.steps();
  int currentStepIndex = routeSteps.size() - 2;
  int upcomingStepIndex = routeSteps.size() - 1;
  LegStep currentStep = routeSteps.get(currentStepIndex);
  LegStep upcomingStep = routeSteps.get(upcomingStepIndex);
  RouteProgress routeProgress = buildRouteProgress(first, route, currentStep, upcomingStep);
  BannerInstructionMilestone bannerInstructionMilestone = mock(BannerInstructionMilestone.class);
  List<BannerInstructions> currentStepBannerInstructions = currentStep.bannerInstructions();
  buildBannerInstruction(first, bannerInstructionMilestone, currentStepBannerInstructions);

  RouteUtils routeUtils = new RouteUtils();

  boolean isArrivalEvent = routeUtils.isArrivalEvent(routeProgress, bannerInstructionMilestone);

  assertFalse(isArrivalEvent);
}
 
Example #6
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapboxNavigation.java    License: MIT License 6 votes vote down vote up
/**
 * Calling This begins a new navigation session using the provided directions route. this API is
 * also intended to be used when a reroute occurs passing in the updated directions route.
 * <p>
 * On initial start of the navigation session, the navigation services gets created and bound to
 * your activity. Unless disabled, a notification will be displayed to the user and will remain
 * until the service stops running in the background.
 * </p><p>
 * The directions route should be acquired by building a {@link NavigationRoute} object and
 * calling {@link NavigationRoute#getRoute(Callback)} on it. Using navigation route request a
 * route with the required parameters needed while at the same time, allowing for flexibility in
 * other parts of the request.
 * </p>
 *
 * @param directionsRoute a {@link DirectionsRoute} that makes up the path your user should
 *                        traverse along
 * @since 0.1.0
 */
public void startNavigation(@NonNull DirectionsRoute directionsRoute) {
  ValidationUtils.validDirectionsRoute(directionsRoute, options.defaultMilestonesEnabled());
  this.directionsRoute = directionsRoute;
  Timber.d("MapboxNavigation startNavigation called.");
  if (!isBound) {
    // Begin telemetry session
    navigationTelemetry.startSession(directionsRoute);

    // Start the NavigationService
    Intent intent = getServiceIntent();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      applicationContext.startForegroundService(intent);
    } else {
      applicationContext.startService(intent);
    }
    applicationContext.bindService(intent, this, Context.BIND_AUTO_CREATE);

    // Send navigation event running: true
    navigationEventDispatcher.onNavigationEvent(true);
  } else {
    // Update telemetry directions route
    navigationTelemetry.updateSessionRoute(directionsRoute);
  }
}
 
Example #7
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteStepProgressTest.java    License: MIT License 6 votes vote down vote up
@Test
public void distanceTraveled_equalsStepDistanceAtEndOfStep() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);
  int stepIndex = 3;
  int legIndex = 0;
  double stepDistanceRemaining = 0;
  double legDistanceRemaining = firstLeg.distance();
  double distanceRemaining = route.distance();
  RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, stepIndex, legIndex);
  RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();

  assertEquals(firstLeg.steps().get(3).distance(),
    routeStepProgress.distanceTraveled(), BaseTest.DELTA);
}
 
Example #8
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteStepProgressTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getDurationRemaining_equalsStepDurationAtBeginning() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);
  LegStep fourthStep = firstLeg.steps().get(5);
  double stepDuration = fourthStep.duration();
  int stepIndex = 5;
  int legIndex = 0;
  double stepDistanceRemaining = firstLeg.steps().get(stepIndex).distance();
  double legDistanceRemaining = firstLeg.distance();
  double distanceRemaining = route.distance();
  RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, stepIndex, legIndex);

  RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
  double durationRemaining = routeStepProgress.durationRemaining();

  assertEquals(stepDuration, durationRemaining, BaseTest.DELTA);
}
 
Example #9
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelper.java    License: MIT License 5 votes vote down vote up
/**
 * Takes in the leg distance remaining value already calculated and if additional legs need to be
 * traversed along after the current one, adds those distances and returns the new distance.
 * Otherwise, if the route only contains one leg or the users on the last leg, this value will
 * equal the leg distance remaining.
 */
static double routeDistanceRemaining(double legDistanceRemaining, int legIndex,
                                     DirectionsRoute directionsRoute) {
  if (directionsRoute.legs().size() < 2) {
    return legDistanceRemaining;
  }

  for (int i = legIndex + 1; i < directionsRoute.legs().size(); i++) {
    legDistanceRemaining += directionsRoute.legs().get(i).distance();
  }
  return legDistanceRemaining;
}
 
Example #10
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteProgressTest.java    License: MIT License 5 votes vote down vote up
@Test
public void durationRemaining_equalsRouteDurationAtBeginning() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteProgress beginningRouteProgress = buildBeginningOfLegRouteProgress(route);

  double durationRemaining = route.duration();
  double progressDurationRemaining = beginningRouteProgress.durationRemaining();

  assertEquals(durationRemaining, progressDurationRemaining, BaseTest.DELTA);
}
 
Example #11
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationHelper.java    License: MIT License 5 votes vote down vote up
/**
 * Takes in the already calculated step distance and iterates through the step list from the
 * step index value plus one till the end of the leg.
 */
static double legDistanceRemaining(double stepDistanceRemaining, int legIndex, int stepIndex,
                                   DirectionsRoute directionsRoute) {
  List<LegStep> steps = directionsRoute.legs().get(legIndex).steps();
  if ((steps.size() < stepIndex + 1)) {
    return stepDistanceRemaining;
  }
  for (int i = stepIndex + 1; i < steps.size(); i++) {
    stepDistanceRemaining += steps.get(i).distance();
  }
  return stepDistanceRemaining;
}
 
Example #12
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationPresenter.java    License: MIT License 5 votes vote down vote up
void onRouteUpdate(DirectionsRoute directionsRoute) {
  view.drawRoute(directionsRoute);
  if (!resumeState) {
    view.updateWaynameVisibility(true);
    view.startCamera(directionsRoute);
  }
}
 
Example #13
Source Project: graphhopper-navigation-android   Author: graphhopper   File: TriggerPropertyTest.java    License: MIT License 5 votes vote down vote up
private RouteProgress buildTestRouteProgressForTrigger() throws Exception {
  Gson gson = new GsonBuilder()
    .registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
  String body = loadJsonFixture(ROUTE_FIXTURE);
  DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);

  DirectionsRoute route = response.routes().get(0);
  double distanceRemaining = route.distance();
  double legDistanceRemaining = route.legs().get(0).distance();
  double stepDistanceRemaining = route.legs().get(0).steps().get(0).distance();
  return buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, 1, 0);
}
 
Example #14
Source Project: graphhopper-navigation-android   Author: graphhopper   File: SimpleCamera.java    License: MIT License 5 votes vote down vote up
private List<Point> generateRouteCoordinates(DirectionsRoute route) {
  if (route == null) {
    return Collections.emptyList();
  }
  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  return lineString.coordinates();
}
 
Example #15
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteProgressTest.java    License: MIT License 5 votes vote down vote up
@Test
public void currentLeg_returnsCurrentLeg() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteProgress beginningRouteProgress = buildBeginningOfLegRouteProgress(route);

  assertEquals(route.legs().get(0), beginningRouteProgress.currentLeg());
}
 
Example #16
Source Project: graphhopper-navigation-android   Author: graphhopper   File: StepMilestoneTest.java    License: MIT License 5 votes vote down vote up
private RouteProgress buildStepMilestoneRouteProgress() throws Exception {
  Gson gson = new GsonBuilder()
    .registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
  String body = loadJsonFixture(ROUTE_FIXTURE);
  DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
  DirectionsRoute route = response.routes().get(0);
  double distanceRemaining = route.distance();
  double legDistanceRemaining = route.legs().get(0).distance();
  double stepDistanceRemaining = route.legs().get(0).steps().get(0).distance();
  return buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, 1, 0);
}
 
Example #17
Source Project: graphhopper-navigation-android   Author: graphhopper   File: TriggerTest.java    License: MIT License 5 votes vote down vote up
private RouteProgress buildTriggerRouteProgress() throws Exception {
  Gson gson = new GsonBuilder()
    .registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
  String body = loadJsonFixture(ROUTE_FIXTURE);
  DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
  DirectionsRoute route = response.routes().get(0);
  int stepDistanceRemaining = (int) route.legs().get(0).steps().get(0).distance();
  int legDistanceRemaining = route.legs().get(0).distance().intValue();
  int routeDistance = route.distance().intValue();
  return buildTestRouteProgress(route, stepDistanceRemaining, legDistanceRemaining,
    routeDistance, 1, 0);
}
 
Example #18
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteStepProgressTest.java    License: MIT License 5 votes vote down vote up
@Test
public void durationRemaining_equalsZeroAtEndOfStep() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);
  int stepIndex = 3;
  int legIndex = 0;
  double stepDistanceRemaining = 0;
  double legDistanceRemaining = firstLeg.distance();
  double distanceRemaining = route.distance();
  RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining,
    legDistanceRemaining, distanceRemaining, stepIndex, legIndex);
  RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();

  assertEquals(0, routeStepProgress.durationRemaining(), BaseTest.DELTA);
}
 
Example #19
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteProgressTest.java    License: MIT License 5 votes vote down vote up
@Test
public void multiLeg_distanceRemaining_equalsRouteDistanceAtBeginning() throws Exception {
  DirectionsRoute multiLegRoute = buildMultipleLegRoute();
  RouteProgress routeProgress = buildBeginningOfLegRouteProgress(multiLegRoute);

  assertEquals(multiLegRoute.distance(), routeProgress.distanceRemaining(), LARGE_DELTA);
}
 
Example #20
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ViewRouteFetcher.java    License: MIT License 5 votes vote down vote up
private String obtainRouteLegDescriptionFrom(DirectionsRoute route) {
  List<RouteLeg> routeLegs = route.legs();
  StringBuilder routeLegDescription = new StringBuilder();
  for (RouteLeg leg : routeLegs) {
    routeLegDescription.append(leg.summary());
  }
  return routeLegDescription.toString();
}
 
Example #21
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private void generateFeatureCollectionList(List<DirectionsRoute> directionsRoutes) {
  // Each route contains traffic information and should be recreated considering this traffic
  // information.
  for (int i = 0; i < directionsRoutes.size(); i++) {
    featureCollections.add(addTrafficToSource(directionsRoutes.get(i), i));
  }

  // Add the waypoint geometries to represent them as an icon
  featureCollections.add(
    waypointFeatureCollection(directionsRoutes.get(primaryRouteIndex))
  );
}
 
Example #22
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * The routes also display an icon for each waypoint in the route, we use symbol layers for this.
 */
private FeatureCollection waypointFeatureCollection(DirectionsRoute route) {
  final List<Feature> waypointFeatures = new ArrayList<>();
  for (RouteLeg leg : route.legs()) {
    waypointFeatures.add(getPointFromLineString(leg, 0));
    waypointFeatures.add(getPointFromLineString(leg, leg.steps().size() - 1));
  }
  return FeatureCollection.fromFeatures(waypointFeatures);
}
 
Example #23
Source Project: graphhopper-navigation-android   Author: graphhopper   File: ToleranceUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void dynamicRerouteDistanceTolerance_userJustPastTheIntersection() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteProgress routeProgress = buildDefaultTestRouteProgress();
  double distanceToIntersection = route.distance();
  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS);

  double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress);

  assertEquals(50.0, tolerance, DELTA);
}
 
Example #24
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteLegProgressTest.java    License: MIT License 5 votes vote down vote up
@Test
public void currentStep_returnsCurrentStep() throws Exception {
  RouteProgress routeProgress = buildDefaultTestRouteProgress();
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteLeg firstLeg = route.legs().get(0);

  routeProgress = routeProgress.toBuilder().stepIndex(5).build();

  assertEquals(
    firstLeg.steps().get(5).geometry(), routeProgress.currentLegProgress().currentStep().geometry()
  );
  assertNotSame(
    firstLeg.steps().get(6).geometry(), routeProgress.currentLegProgress().currentStep().geometry()
  );
}
 
Example #25
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationFasterRouteListenerTest.java    License: MIT License 5 votes vote down vote up
@NonNull
private DirectionsResponse buildDirectionsResponse() {
  DirectionsResponse response = mock(DirectionsResponse.class);
  List<DirectionsRoute> routes = new ArrayList<>();
  routes.add(mock(DirectionsRoute.class));
  when(response.routes()).thenReturn(routes);
  return response;
}
 
Example #26
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * If the {@link DirectionsRoute} request contains congestion information via annotations, breakup
 * the source into pieces so data-driven styling can be used to change the route colors
 * accordingly.
 */
private FeatureCollection addTrafficToSource(DirectionsRoute route, int index) {
  final List<Feature> features = new ArrayList<>();
  LineString originalGeometry = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  buildRouteFeatureFromGeometry(index, features, originalGeometry);
  routeLineStrings.put(originalGeometry, route);

  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  buildTrafficFeaturesFromRoute(route, index, features, lineString);
  return FeatureCollection.fromFeatures(features);
}
 
Example #27
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RouteProgressTest.java    License: MIT License 5 votes vote down vote up
@Test
public void fractionTraveled_equalsZeroAtBeginning() throws Exception {
  DirectionsRoute route = buildTestDirectionsRoute();
  RouteProgress beginningRouteProgress = buildBeginningOfLegRouteProgress(route);

  assertEquals(0, beginningRouteProgress.fractionTraveled(), BaseTest.LARGE_DELTA);
}
 
Example #28
Source Project: graphhopper-navigation-android   Author: graphhopper   File: DynamicCameraTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onInformationFromRoute_engineCreatesOverviewPointList() throws Exception {
  DynamicCamera cameraEngine = buildDynamicCamera();
  DirectionsRoute route = buildDirectionsRoute();
  List<Point> routePoints = generateRouteCoordinates(route);
  RouteInformation routeInformation = RouteInformation.create(route, null, null);

  List<Point> overviewPoints = cameraEngine.overview(routeInformation);

  assertEquals(routePoints, overviewPoints);
}
 
Example #29
Source Project: mapbox-java   Author: mapbox   File: DirectionsResponseFactory.java    License: MIT License 5 votes vote down vote up
private List<DirectionsRoute> generateRouteOptions(Response<DirectionsResponse> response) {
  List<DirectionsRoute> routes = response.body().routes();
  List<DirectionsRoute> modifiedRoutes = new ArrayList<>();
  for (DirectionsRoute route : routes) {
    modifiedRoutes.add(route.toBuilder().routeOptions(
      RouteOptions.builder()
        .profile(mapboxDirections.profile())
        .coordinates(mapboxDirections.coordinates())
        .waypointIndicesList(ParseUtils.parseToIntegers(mapboxDirections.waypointIndices()))
        .waypointNamesList(ParseUtils.parseToStrings(mapboxDirections.waypointNames()))
        .waypointTargetsList(ParseUtils.parseToPoints(mapboxDirections.waypointTargets()))
        .continueStraight(mapboxDirections.continueStraight())
        .annotationsList(ParseUtils.parseToStrings(mapboxDirections.annotation()))
        .approachesList(ParseUtils.parseToStrings(mapboxDirections.approaches()))
        .bearingsList(ParseUtils.parseToListOfListOfDoubles(mapboxDirections.bearing()))
        .alternatives(mapboxDirections.alternatives())
        .language(mapboxDirections.language())
        .radiusesList(ParseUtils.parseToDoubles(mapboxDirections.radius()))
        .user(mapboxDirections.user())
        .voiceInstructions(mapboxDirections.voiceInstructions())
        .bannerInstructions(mapboxDirections.bannerInstructions())
        .roundaboutExits(mapboxDirections.roundaboutExits())
        .geometries(mapboxDirections.geometries())
        .overview(mapboxDirections.overview())
        .steps(mapboxDirections.steps())
        .exclude(mapboxDirections.exclude())
        .voiceUnits(mapboxDirections.voiceUnits())
        .accessToken(mapboxDirections.accessToken())
        .requestUuid(response.body().uuid())
        .baseUrl(mapboxDirections.baseUrl())
        .walkingOptions(mapboxDirections.walkingOptions())
        .build()
    ).build());
  }
  return modifiedRoutes;
}
 
Example #30
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationRouteProcessor.java    License: MIT License 5 votes vote down vote up
private RouteProgress assembleRouteProgress(DirectionsRoute route) {
  int legIndex = indices.legIndex();
  int stepIndex = indices.stepIndex();

  double legDistanceRemaining = legDistanceRemaining(stepDistanceRemaining, legIndex, stepIndex, route);
  double routeDistanceRemaining = routeDistanceRemaining(legDistanceRemaining, legIndex, route);
  currentLegAnnotation = createCurrentAnnotation(currentLegAnnotation, currentLeg, legDistanceRemaining);
  double stepDistanceTraveled = currentStep.distance() - stepDistanceRemaining;

  StepIntersection currentIntersection = findCurrentIntersection(
    currentIntersections, currentIntersectionDistances, stepDistanceTraveled
  );
  StepIntersection upcomingIntersection = findUpcomingIntersection(
    currentIntersections, upcomingStep, currentIntersection
  );

  RouteProgress.Builder progressBuilder = RouteProgress.builder()
    .stepDistanceRemaining(stepDistanceRemaining)
    .legDistanceRemaining(legDistanceRemaining)
    .distanceRemaining(routeDistanceRemaining)
    .directionsRoute(route)
    .currentStepPoints(currentStepPoints)
    .upcomingStepPoints(upcomingStepPoints)
    .stepIndex(stepIndex)
    .legIndex(legIndex)
    .intersections(currentIntersections)
    .currentIntersection(currentIntersection)
    .upcomingIntersection(upcomingIntersection)
    .intersectionDistancesAlongStep(currentIntersectionDistances)
    .currentLegAnnotation(currentLegAnnotation);

  addUpcomingStepPoints(progressBuilder);
  return progressBuilder.build();
}