use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class FasterRouteDetector method isFasterRoute.
@Override
public boolean isFasterRoute(DirectionsResponse response, RouteProgress routeProgress) {
if (validRouteResponse(response)) {
double currentDurationRemaining = routeProgress.durationRemaining();
DirectionsRoute newRoute = response.routes().get(0);
if (hasLegs(newRoute)) {
// Extract the first leg
RouteLeg routeLeg = newRoute.legs().get(0);
if (hasAtLeastTwoSteps(routeLeg)) {
// Extract the first two steps
LegStep firstStep = routeLeg.steps().get(0);
LegStep secondStep = routeLeg.steps().get(1);
// Check for valid first and second steps of the new route
if (!validFirstStep(firstStep) || !validSecondStep(secondStep, routeProgress)) {
return false;
}
}
}
// New route must be at least 10% faster
if (newRoute.duration() <= (0.9 * currentDurationRemaining)) {
return true;
}
}
return false;
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class MetricsRouteProgress method retrieveRouteDestination.
private Point retrieveRouteDestination(DirectionsRoute route) {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
LegStep lastStep = lastLeg.steps().get(lastLeg.steps().size() - 1);
StepManeuver finalManuever = lastStep.maneuver();
if (finalManuever.location() != null) {
return finalManuever.location();
}
return Point.fromLngLat(0d, 0d);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteProgressTest method multiLeg_getFractionTraveled_equalsCorrectValueAtIntervals.
// TODO check fut
@Test
public void multiLeg_getFractionTraveled_equalsCorrectValueAtIntervals() {
// Chop the line in small pieces
for (RouteLeg leg : multiLegRoute.legs()) {
for (int step = 0; step < leg.steps().size(); step++) {
RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(multiLegRoute.legs().get(0).steps().get(0).distance()).legDistanceRemaining(multiLegRoute.legs().get(0).distance()).distanceRemaining(multiLegRoute.distance()).directionsRoute(multiLegRoute).stepIndex(step).legIndex(0).build();
float fractionRemaining = (float) (routeProgress.distanceTraveled() / multiLegRoute.distance());
assertEquals(fractionRemaining, routeProgress.fractionTraveled(), BaseTest.LARGE_DELTA);
}
}
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class MockNavigationActivity method calculateRoute.
private void calculateRoute() {
Location userLocation = mapboxMap.getMyLocation();
if (userLocation == null) {
Timber.d("calculateRoute: User location is null, therefore, origin can't be set.");
return;
}
Point origin = Point.fromLngLat(userLocation.getLongitude(), userLocation.getLatitude());
if (TurfMeasurement.distance(origin, destination, TurfConstants.UNIT_METERS) < 50) {
startRouteButton.setVisibility(View.GONE);
return;
}
final NavigationRoute.Builder navigationRouteBuilder = NavigationRoute.builder().accessToken(Mapbox.getAccessToken());
navigationRouteBuilder.origin(origin);
navigationRouteBuilder.destination(destination);
if (waypoint != null) {
navigationRouteBuilder.addWaypoint(waypoint);
}
navigationRouteBuilder.build().getRoute(new Callback<DirectionsResponse>() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
Timber.d("Url: %s", call.request().url().toString());
if (response.body() != null) {
if (!response.body().routes().isEmpty()) {
DirectionsRoute directionsRoute = response.body().routes().get(0);
MockNavigationActivity.this.route = directionsRoute;
navigationMapRoute.addRoutes(response.body().routes());
}
}
}
@Override
public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
Timber.e("onFailure: navigation.getRoute()", throwable);
}
});
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationMapRoute method waypointFeatureCollection.
/**
* The routes also display an icon for each waypoint in the route, we use symbol layers for this.
*/
private static 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);
}
Aggregations