Java Code Examples for com.mapbox.services.android.navigation.v5.navigation.NavigationRoute#Builder

The following examples show how to use com.mapbox.services.android.navigation.v5.navigation.NavigationRoute#Builder . 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 File: NavigationLauncherActivity.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
private void fetchRoute() {
  NavigationRoute.Builder builder = NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(currentLocation)
    .destination(destination)
    .alternatives(true);
  setFieldsFromSharedPreferences(builder);
  builder.build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        if (validRouteResponse(response)) {
          hideLoading();
          route = response.body().routes().get(0);
          if (route.distance() > 25d) {
            launchRouteBtn.setEnabled(true);
            mapRoute.addRoutes(response.body().routes());
            boundCameraToRoute();
          } else {
            Snackbar.make(mapView, R.string.error_select_longer_route, Snackbar.LENGTH_SHORT).show();
          }
        }
      }
    });
  loading.setVisibility(View.VISIBLE);
}
 
Example 2
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
@Nullable
private NavigationRoute.Builder buildRequestFromLocation(Location location, RouteProgress progress) {
  Context context = contextWeakReference.get();
  if (context == null) {
    return null;
  }
  Point origin = Point.fromLngLat(location.getLongitude(), location.getLatitude());
  Double bearing = location.hasBearing() ? Float.valueOf(location.getBearing()).doubleValue() : null;
  RouteOptions options = progress.directionsRoute().routeOptions();
  NavigationRoute.Builder builder = NavigationRoute.builder(context)
    .origin(origin, bearing, BEARING_TOLERANCE)
    .routeOptions(options);

  List<Point> remainingWaypoints = routeUtils.calculateRemainingWaypoints(progress);
  if (remainingWaypoints == null) {
    Timber.e("An error occurred fetching a new route");
    return null;
  }
  addDestination(remainingWaypoints, builder);
  addWaypoints(remainingWaypoints, builder);
  addWaypointNames(progress, builder);
  addApproaches(progress, builder);
  return builder;
}
 
Example 3
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void addWaypoints(List<Point> remainingCoordinates, NavigationRoute.Builder builder) {
  if (!remainingCoordinates.isEmpty()) {
    for (Point coordinate : remainingCoordinates) {
      builder.addWaypoint(coordinate);
    }
  }
}
 
Example 4
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void setFieldsFromSharedPreferences(NavigationRoute.Builder builder) {
  builder
    .language(getLanguageFromSharedPreferences())
    .voiceUnits(getUnitTypeFromSharedPreferences());
}
 
Example 5
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void addDestination(List<Point> remainingWaypoints, NavigationRoute.Builder builder) {
  if (!remainingWaypoints.isEmpty()) {
    builder.destination(retrieveDestinationWaypoint(remainingWaypoints));
  }
}
 
Example 6
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void addWaypointNames(RouteProgress progress, NavigationRoute.Builder builder) {
  String[] remainingWaypointNames = routeUtils.calculateRemainingWaypointNames(progress);
  if (remainingWaypointNames != null) {
    builder.addWaypointNames(remainingWaypointNames);
  }
}
 
Example 7
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void addApproaches(RouteProgress progress, NavigationRoute.Builder builder) {
  String[] remainingApproaches = calculateRemainingApproaches(progress);
  if (remainingApproaches != null) {
    builder.addApproaches(remainingApproaches);
  }
}
 
Example 8
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void executeRouteCall(NavigationRoute.Builder builder) {
  if (builder != null) {
    builder.accessToken(accessToken);
    builder.build().getRoute(directionsResponseCallback);
  }
}
 
Example 9
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 4 votes vote down vote up
private void setFieldsFromSharedPreferences(NavigationRoute.Builder builder) {
    builder
            .language(getLanguageFromSharedPreferences())
            .voiceUnits(getUnitTypeFromSharedPreferences())
            .profile(getRouteProfileFromSharedPreferences());
}
 
Example 10
Source File: RouteFetcher.java    From graphhopper-navigation-android with MIT License 3 votes vote down vote up
/**
 * Calculates a new {@link com.mapbox.api.directions.v5.models.DirectionsRoute} given
 * the current {@link Location} and {@link RouteProgress} along the route.
 * <p>
 * Uses {@link RouteOptions#coordinates()} and {@link RouteProgress#remainingWaypoints()}
 * to determine the amount of remaining waypoints there are along the given route.
 *
 * @param location      current location of the device
 * @param routeProgress for remaining waypoints along the route
 * @since 0.13.0
 */
public void findRouteFromRouteProgress(Location location, RouteProgress routeProgress) {
  if (isInvalidProgress(location, routeProgress)) {
    return;
  }
  this.routeProgress = routeProgress;
  NavigationRoute.Builder builder = buildRequestFromLocation(location, routeProgress);
  executeRouteCall(builder);
}