Search in sources :

Example 16 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute 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)

Example 17 with DirectionsRoute

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

the class DynamicCameraTest method buildDirectionsRoute.

private 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);
    return response.routes().get(0);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse)

Example 18 with DirectionsRoute

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

the class NavigationMapRoute method checkNewRouteFound.

private void checkNewRouteFound(int currentRouteIndex) {
    if (currentRouteIndex != primaryRouteIndex) {
        updateRoute();
        boolean isValidPrimaryIndex = primaryRouteIndex >= 0 && primaryRouteIndex < directionsRoutes.size();
        if (isValidPrimaryIndex && onRouteSelectionChangeListener != null) {
            DirectionsRoute selectedRoute = directionsRoutes.get(primaryRouteIndex);
            onRouteSelectionChangeListener.onNewPrimaryRouteSelected(selectedRoute);
        }
    }
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute)

Example 19 with DirectionsRoute

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

the class NavigationMapRoute method buildTrafficFeaturesFromRoute.

private void buildTrafficFeaturesFromRoute(DirectionsRoute route, int index, List<Feature> features, LineString lineString) {
    for (RouteLeg leg : route.legs()) {
        if (leg.annotation() != null && leg.annotation().congestion() != null) {
            for (int i = 0; i < leg.annotation().congestion().size(); i++) {
                // See https://github.com/mapbox/mapbox-navigation-android/issues/353
                if (leg.annotation().congestion().size() + 1 <= lineString.getCoordinates().size()) {
                    double[] startCoord = lineString.getCoordinates().get(i).getCoordinates();
                    double[] endCoord = lineString.getCoordinates().get(i + 1).getCoordinates();
                    LineString congestionLineString = LineString.fromCoordinates(new double[][] { startCoord, endCoord });
                    Feature feature = Feature.fromGeometry(congestionLineString);
                    feature.addStringProperty(CONGESTION_KEY, leg.annotation().congestion().get(i));
                    feature.addStringProperty(SOURCE_KEY, String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_SOURCE_ID, index));
                    feature.addNumberProperty(INDEX_KEY, index);
                    features.add(feature);
                }
            }
        } else {
            Feature feature = Feature.fromGeometry(lineString);
            features.add(feature);
        }
    }
}
Also used : LineString(com.mapbox.services.commons.geojson.LineString) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) Feature(com.mapbox.services.commons.geojson.Feature) Point(com.mapbox.services.commons.geojson.Point)

Example 20 with DirectionsRoute

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

the class RouteViewModel method obtainRouteLegDescriptionFrom.

private String obtainRouteLegDescriptionFrom(DirectionsRoute route) {
    List<RouteLeg> routeLegs = route.legs();
    StringBuilder routeLegDescription = new StringBuilder();
    for (RouteLeg leg : routeLegs) {
        routeLegDescription.append(leg.summary());
    }
    return routeLegDescription.toString();
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg)

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