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;
}
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();
}
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();
}
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);
}
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;
}
}
}
Aggregations