Search in sources :

Example 11 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class StepMilestoneTest method setup.

@Before
public void setup() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
    String body = loadJsonFixture(PRECISION_6);
    DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
    DirectionsRoute route = response.routes().get(0);
    routeProgress = RouteProgress.builder().directionsRoute(route).distanceRemaining(route.distance()).legDistanceRemaining(route.legs().get(0).distance()).stepDistanceRemaining(route.legs().get(0).steps().get(0).distance()).legIndex(0).stepIndex(1).build();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Gson(com.google.gson.Gson) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Before(org.junit.Before)

Example 12 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class TriggerTest method setup.

@Before
public void setup() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
    String body = loadJsonFixture(PRECISION_6);
    DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
    DirectionsRoute route = response.routes().get(0);
    Location location = new Location("test");
    List<Point> coords = PolylineUtils.decode(route.legs().get(0).steps().get(1).geometry(), Constants.PRECISION_6);
    location.setLatitude(coords.get(0).latitude());
    location.setLongitude(coords.get(0).longitude());
    routeProgress = RouteProgress.builder().directionsRoute(route).distanceRemaining(route.distance()).legDistanceRemaining(route.legs().get(0).distance()).stepDistanceRemaining(route.legs().get(0).steps().get(0).distance()).legIndex(0).stepIndex(1).build();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Gson(com.google.gson.Gson) Point(com.mapbox.geojson.Point) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Location(android.location.Location) Before(org.junit.Before)

Example 13 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class FasterRouteDetectorTest method obtainDefaultRouteProgress.

private RouteProgress obtainDefaultRouteProgress() throws Exception {
    DirectionsRoute aRoute = obtainADirectionsRoute();
    RouteProgress defaultRouteProgress = RouteProgress.builder().stepDistanceRemaining(100).legDistanceRemaining(700).distanceRemaining(1000).directionsRoute(aRoute).stepIndex(0).legIndex(0).build();
    return defaultRouteProgress;
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)

Example 14 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class FasterRouteDetectorTest method onFasterRouteResponse_isFasterRouteIsTrue.

@Test
public void onFasterRouteResponse_isFasterRouteIsTrue() throws Exception {
    FasterRoute fasterRouteEngine = navigation.getFasterRouteEngine();
    // Create current progress
    RouteProgress currentProgress = obtainDefaultRouteProgress();
    DirectionsRoute longerRoute = currentProgress.directionsRoute().toBuilder().duration(// Current route duration is very long
    10000000d).build();
    currentProgress = currentProgress.toBuilder().directionsRoute(longerRoute).build();
    // Create new direction response
    DirectionsResponse response = obtainADirectionsResponse();
    boolean isFasterRoute = fasterRouteEngine.isFasterRoute(response, currentProgress);
    assertTrue(isFasterRoute);
}
Also used : FasterRoute(com.mapbox.services.android.navigation.v5.route.FasterRoute) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 15 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method isArrivalEvent_returnsTrueWhenUpcomingManeuverTypeIsArrival_andIsValidMetersRemaining.

@Test
public void isArrivalEvent_returnsTrueWhenUpcomingManeuverTypeIsArrival_andIsValidMetersRemaining() throws Exception {
    DirectionsRoute aRoute = buildDirectionsRoute();
    int lastStepIndex = obtainLastStepIndex(aRoute);
    RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
    RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().legDistanceRemaining(30).stepIndex(lastStepIndex - 1).build();
    boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
    assertTrue(isArrivalEvent);
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Aggregations

DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)25 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)14 Gson (com.google.gson.Gson)11 GsonBuilder (com.google.gson.GsonBuilder)11 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)10 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)10 Test (org.junit.Test)10 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)9 Before (org.junit.Before)7 Point (com.mapbox.geojson.Point)6 Location (android.location.Location)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 LineString (com.mapbox.geojson.LineString)3 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 Feature (com.mapbox.services.commons.geojson.Feature)2 ArrayList (java.util.ArrayList)2 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)1 LineString (com.mapbox.services.commons.geojson.LineString)1 Point (com.mapbox.services.commons.geojson.Point)1