Search in sources :

Example 36 with DirectionsRoute

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

the class NavigationMapRoute method findClickedRoute.

private boolean findClickedRoute(@NonNull LatLng point) {
    HashMap<Double, DirectionsRoute> routeDistancesAwayFromClick = new HashMap<>();
    com.mapbox.geojson.Point clickPoint = com.mapbox.geojson.Point.fromLngLat(point.getLongitude(), point.getLatitude());
    if (calculateClickDistancesFromRoutes(routeDistancesAwayFromClick, clickPoint)) {
        return true;
    }
    List<Double> distancesAwayFromClick = new ArrayList<>(routeDistancesAwayFromClick.keySet());
    Collections.sort(distancesAwayFromClick);
    DirectionsRoute clickedRoute = routeDistancesAwayFromClick.get(distancesAwayFromClick.get(0));
    primaryRouteIndex = directionsRoutes.indexOf(clickedRoute);
    return false;
}
Also used : HashMap(java.util.HashMap) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) ArrayList(java.util.ArrayList)

Example 37 with DirectionsRoute

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

the class RouteViewModel method extractRouteFromOptions.

/**
 * Extracts the {@link DirectionsRoute}, adds a destination marker,
 * and starts navigation.
 *
 * @param options containing route
 */
private void extractRouteFromOptions(NavigationViewOptions options) {
    DirectionsRoute route = options.directionsRoute();
    if (route != null) {
        cacheRouteInformation(options, route);
        this.route.setValue(route);
    }
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute)

Example 38 with DirectionsRoute

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

the class RouteViewModel method processRoute.

private void processRoute(@NonNull Response<DirectionsResponse> response) {
    if (isValidRoute(response)) {
        List<DirectionsRoute> routes = response.body().routes();
        DirectionsRoute bestRoute = routes.get(FIRST_ROUTE);
        DirectionsRoute chosenRoute = route.getValue();
        if (isNavigationRunning(chosenRoute)) {
            bestRoute = obtainMostSimilarRoute(routes, bestRoute, chosenRoute);
        }
        route.setValue(bestRoute);
    }
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute)

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