Search in sources :

Example 11 with LegStep

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

the class MeasurementUtilsTest method userTrueDistanceFromStep_onePointStepGeometryWithDifferentRawPoint.

@Test
public void userTrueDistanceFromStep_onePointStepGeometryWithDifferentRawPoint() {
    Point futurePoint = Point.fromLngLat(-95.3676974, 29.7589382);
    List<Point> geometryPoints = new ArrayList<>();
    geometryPoints.add(Point.fromLngLat(-95.8427, 29.7757));
    geometryPoints.add(futurePoint);
    double[] rawLocation = { 0, 0 };
    LegStep step = getLegStep(rawLocation, geometryPoints);
    double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step);
    assertEquals(0.04457271773629306d, distance, DELTA);
}
Also used : ArrayList(java.util.ArrayList) Point(com.mapbox.geojson.Point) LegStep(com.mapbox.api.directions.v5.models.LegStep) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 12 with LegStep

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

the class MapboxNavigationNotification method updateNotificationViews.

/**
 * With each location update and new routeProgress, the notification is checked and updated if any
 * information has changed.
 *
 * @param routeProgress the latest RouteProgress object
 */
private void updateNotificationViews(RouteProgress routeProgress) {
    // Instruction
    updateInstructionText(routeProgress.currentLegProgress().currentStep());
    // Distance
    updateDistanceText(routeProgress);
    // Arrival Time
    updateArrivalTime(routeProgress);
    // Get upcoming step for maneuver image - current step if null
    LegStep step = routeProgress.currentLegProgress().upComingStep() != null ? routeProgress.currentLegProgress().upComingStep() : routeProgress.currentLegProgress().currentStep();
    // Maneuver Image
    updateManeuverImage(step);
    notificationManager.notify(NAVIGATION_NOTIFICATION_ID, notificationBuilder.build());
}
Also used : LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 13 with LegStep

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

the class FasterRouteDetector method isFasterRoute.

@Override
public boolean isFasterRoute(DirectionsResponse response, RouteProgress routeProgress) {
    if (validRouteResponse(response)) {
        double currentDurationRemaining = routeProgress.durationRemaining();
        DirectionsRoute newRoute = response.routes().get(0);
        if (hasLegs(newRoute)) {
            // Extract the first leg
            RouteLeg routeLeg = newRoute.legs().get(0);
            if (hasAtLeastTwoSteps(routeLeg)) {
                // Extract the first two steps
                LegStep firstStep = routeLeg.steps().get(0);
                LegStep secondStep = routeLeg.steps().get(1);
                // Check for valid first and second steps of the new route
                if (!validFirstStep(firstStep) || !validSecondStep(secondStep, routeProgress)) {
                    return false;
                }
            }
        }
        // New route must be at least 10% faster
        if (newRoute.duration() <= (0.9 * currentDurationRemaining)) {
            return true;
        }
    }
    return false;
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 14 with LegStep

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

the class MetricsRouteProgress method retrieveRouteDestination.

private Point retrieveRouteDestination(DirectionsRoute route) {
    RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
    LegStep lastStep = lastLeg.steps().get(lastLeg.steps().size() - 1);
    StepManeuver finalManuever = lastStep.maneuver();
    if (finalManuever.location() != null) {
        return finalManuever.location();
    }
    return Point.fromLngLat(0d, 0d);
}
Also used : StepManeuver(com.mapbox.api.directions.v5.models.StepManeuver) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 15 with LegStep

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

the class RouteLegProgress method create.

/**
 * Constructor for the route leg progress information.
 *
 * @param routeLeg            the current {@link RouteLeg} the user is traversing along
 * @param stepIndex           the current step index the user is on
 * @param legDistanceRemaining the leg distance remaining which is calculated in navigation engine
 * @param stepDistanceRemaining the step distance remaining which is calculated in navigation engine
 * @since 0.1.0
 */
static RouteLegProgress create(RouteLeg routeLeg, int stepIndex, double legDistanceRemaining, double stepDistanceRemaining) {
    LegStep nextStep = stepIndex == (routeLeg.steps().size() - 1) ? null : routeLeg.steps().get(stepIndex + 1);
    RouteStepProgress stepProgress = RouteStepProgress.create(routeLeg.steps().get(stepIndex), nextStep, stepDistanceRemaining);
    return new AutoValue_RouteLegProgress(routeLeg, stepIndex, legDistanceRemaining, stepProgress);
}
Also used : LegStep(com.mapbox.api.directions.v5.models.LegStep)

Aggregations

LegStep (com.mapbox.api.directions.v5.models.LegStep)18 Point (com.mapbox.geojson.Point)9 LineString (com.mapbox.geojson.LineString)5 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)3 Location (android.location.Location)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 NonNull (android.support.annotation.NonNull)1 SpannableString (android.text.SpannableString)1 BannerInstructions (com.mapbox.api.directions.v5.models.BannerInstructions)1 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)1 IntersectionLanes (com.mapbox.api.directions.v5.models.IntersectionLanes)1 StepIntersection (com.mapbox.api.directions.v5.models.StepIntersection)1 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1