com.mapbox.services.android.navigation.v5.navigation.NavigationRoute Java Examples

The following examples show how to use com.mapbox.services.android.navigation.v5.navigation.NavigationRoute. 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: 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 #2
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 #3
Source File: NavigationFragment.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute(Point origin, Point destination) {
  NavigationRoute.builder(getContext())
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        directionsRoute = response.body().routes().get(0);
        startNavigation();
      }
    });
}
 
Example #4
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 #5
Source File: OnNavigationReadyIdlingResource.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute(Context context) {
  Point origin = Point.fromLngLat(-77.033987, 38.900123);
  Point destination = Point.fromLngLat(-77.044818, 38.848942);
  NavigationRoute.builder(context)
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .build().getRoute(this);
}
 
Example #6
Source File: EmbeddedNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute() {
  NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(ORIGIN)
    .destination(DESTINATION)
    .alternatives(true)
    .build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        DirectionsRoute directionsRoute = response.body().routes().get(0);
        startNavigation(directionsRoute);
      }
    });
}
 
Example #7
Source File: EndNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute() {
  NavigationRoute builder = NavigationRoute.builder(this)
    .accessToken(getString(R.string.mapbox_access_token))
    .origin(origin)
    .addWaypoint(pickup)
    .destination(destination)
    .alternatives(true)
    .build();
  builder.getRoute(this);
  updateLoadingTo(true);
}
 
Example #8
Source File: WaypointNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute(Point origin, Point destination) {
  NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .alternatives(true)
    .build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        startNavigation(response.body().routes().get(0));
      }
    });
}
 
Example #9
Source File: DualNavigationMapActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute() {
  NavigationRoute builder = NavigationRoute.builder(this)
    .accessToken(getString(R.string.mapbox_access_token))
    .origin(origin)
    .destination(destination)
    .alternatives(true)
    .build();
  builder.getRoute(this);
}
 
Example #10
Source File: RerouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void getRoute(Point origin, Point destination, Float bearing) {
  Double heading = bearing == null ? null : bearing.doubleValue();
  NavigationRoute.builder(this)
    .origin(origin, heading, 90d)
    .destination(destination)
    .accessToken(Mapbox.getAccessToken())
    .build().getRoute(this);
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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);
}