Search in sources :

Example 6 with DirectionsResponse

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

the class BaseTest method buildDirectionsRoute.

protected DirectionsRoute buildDirectionsRoute() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
    String body = loadJsonFixture(DIRECTIONS_PRECISION_6);
    DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
    DirectionsRoute aRoute = response.routes().get(0);
    return aRoute;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Gson(com.google.gson.Gson) LineString(com.mapbox.geojson.LineString) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse)

Example 7 with DirectionsResponse

use of com.mapbox.api.directions.v5.models.DirectionsResponse 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 8 with DirectionsResponse

use of com.mapbox.api.directions.v5.models.DirectionsResponse 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 9 with DirectionsResponse

use of com.mapbox.api.directions.v5.models.DirectionsResponse 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 10 with DirectionsResponse

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

the class RerouteActivity method onResponse.

@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
    Timber.d(call.request().url().toString());
    if (response.body() != null) {
        if (!response.body().routes().isEmpty()) {
            // Extract the route
            DirectionsRoute route = response.body().routes().get(0);
            // Draw it on the map
            drawRoute(route);
            // Start mocking the new route
            resetLocationEngine(route);
            navigation.startNavigation(route);
            mapboxMap.setOnMapClickListener(this);
            tracking = true;
        }
    }
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute)

Aggregations

DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)17 Gson (com.google.gson.Gson)14 GsonBuilder (com.google.gson.GsonBuilder)14 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)11 Before (org.junit.Before)9 Location (android.location.Location)3 Point (com.mapbox.geojson.Point)3 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)2 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)2 Test (org.junit.Test)2 LegStep (com.mapbox.api.directions.v5.models.LegStep)1 LineString (com.mapbox.geojson.LineString)1 NavigationMapRoute (com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute)1 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)1