Search in sources :

Example 21 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method onRouteProgressUpdate.

@Override
public void onRouteProgressUpdate(RouteProgress routeProgress) {
    this.metricProgress = new MetricsRouteProgress(routeProgress);
    boolean isValidDeparture = navigationSessionState.startTimestamp() == null && routeProgress.currentLegProgress().distanceTraveled() > 0;
    if (isValidDeparture) {
        navigationSessionState = navigationSessionState.toBuilder().startTimestamp(new Date()).build();
        updateLifecyclePercentages();
        NavigationMetricsWrapper.departEvent(navigationSessionState, metricProgress, metricLocation.getLocation());
    }
}
Also used : MetricsRouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress) Date(java.util.Date)

Example 22 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method queueFeedbackEvent.

@NonNull
private FeedbackEvent queueFeedbackEvent(@FeedbackEvent.FeedbackType String feedbackType, String description, @FeedbackEvent.FeedbackSource String feedbackSource) {
    updateLifecyclePercentages();
    // Distance completed = previous distance completed + current RouteProgress distance traveled
    double distanceCompleted = navigationSessionState.eventRouteDistanceCompleted() + metricProgress.getDistanceTraveled();
    // Create a new session state given the current navigation session
    SessionState feedbackEventSessionState = navigationSessionState.toBuilder().eventDate(new Date()).eventRouteProgress(metricProgress).eventRouteDistanceCompleted(distanceCompleted).eventLocation(metricLocation.getLocation()).mockLocation(metricLocation.getLocation().getProvider().equals(MOCK_PROVIDER)).build();
    FeedbackEvent feedbackEvent = new FeedbackEvent(feedbackEventSessionState, feedbackSource);
    feedbackEvent.setDescription(description);
    feedbackEvent.setFeedbackType(feedbackType);
    queuedFeedbackEvents.add(feedbackEvent);
    return feedbackEvent;
}
Also used : SessionState(com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState) FeedbackEvent(com.mapbox.services.android.navigation.v5.navigation.metrics.FeedbackEvent) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Example 23 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class SnapToRoute method snapLocationBearing.

/**
 * Creates a snapped bearing for the snapped {@link Location}.
 * <p>
 * This is done by measuring 1 meter ahead of the current step distance traveled and
 * creating a {@link Point} with this distance using {@link TurfMeasurement#along(LineString, double, String)}.
 * <p>
 * If the step distance remaining is zero, the distance ahead is 1 meter into the upcoming step.
 * This way, an accurate bearing is upheld transitioning between steps.
 *
 * @param routeProgress for all current progress values
 * @return float bearing snapped to route
 */
private static float snapLocationBearing(RouteProgress routeProgress) {
    RouteLegProgress legProgress = routeProgress.currentLegProgress();
    RouteStepProgress stepProgress = legProgress.currentStepProgress();
    double distanceTraveled = stepProgress.distanceTraveled();
    double distanceRemaining = stepProgress.distanceRemaining();
    boolean distanceRemainingZero = distanceRemaining == 0;
    // Either want to measure our current step distance traveled + 1 or 1 meter into the upcoming step
    double distanceAhead = distanceRemainingZero ? 1 : distanceTraveled + 1;
    // Create the step linestring from the geometry
    LineString upcomingLineString = createUpcomingLineString(legProgress, distanceRemainingZero);
    LineString currentLineString = createCurrentLineString(legProgress);
    // Measure 1 meter ahead of the users current location, only if the distance remaining isn't zero
    Point futurePoint = createFuturePoint(distanceAhead, upcomingLineString, currentLineString);
    Point currentPoint = TurfMeasurement.along(currentLineString, distanceTraveled, TurfConstants.UNIT_METERS);
    // Get bearing and convert azimuth to degrees
    double azimuth = TurfMeasurement.bearing(currentPoint, futurePoint);
    return (float) MathUtils.wrap(azimuth, 0, 360);
}
Also used : RouteStepProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress) LineString(com.mapbox.geojson.LineString) RouteLegProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteLegProgress) Point(com.mapbox.geojson.Point)

Example 24 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteEngine method fetchRoute.

/**
 * Calculates a new {@link com.mapbox.api.directions.v5.models.DirectionsRoute} given
 * the current {@link Location} and {@link RouteProgress} along the route.
 * <p>
 * Uses {@link RouteOptions#coordinates()} and {@link RouteProgress#remainingWaypoints()}
 * to determine the amount of remaining waypoints there are along the given route.
 *
 * @param location      current location of the device
 * @param routeProgress for remaining waypoints along the route
 * @since 0.10.0
 */
public void fetchRoute(Location location, RouteProgress routeProgress) {
    if (location == null || routeProgress == null) {
        return;
    }
    this.routeProgress = routeProgress;
    Point origin = Point.fromLngLat(location.getLongitude(), location.getLatitude());
    Double bearing = location.hasBearing() ? Float.valueOf(location.getBearing()).doubleValue() : null;
    NavigationRoute.Builder builder = buildRouteRequestFromCurrentLocation(origin, bearing, routeProgress);
    if (builder != null) {
        builder.language(locale).voiceUnits(unitType);
        builder.build().getRoute(this);
    }
}
Also used : Point(com.mapbox.geojson.Point) NavigationRoute(com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)

Example 25 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method isArrivalEvent_returnsTrueWhenUpcomingManeuverTypeIsArrival_andIsValidMetersRemaining.

@Test
public void isArrivalEvent_returnsTrueWhenUpcomingManeuverTypeIsArrival_andIsValidMetersRemaining() throws Exception {
    DirectionsRoute aRoute = buildDirectionsRoute();
    int lastStepIndex = obtainLastStepIndex(aRoute);
    RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
    RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().legDistanceRemaining(30).stepIndex(lastStepIndex - 1).build();
    boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
    assertTrue(isArrivalEvent);
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Aggregations

BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)44 Test (org.junit.Test)44 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)39 Point (com.mapbox.geojson.Point)30 Location (android.location.Location)19 LineString (com.mapbox.geojson.LineString)12 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)10 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)3 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)3 Context (android.content.Context)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 MetricsRouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)2 RouteStepProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress)2 DistanceUtils (com.mapbox.services.android.navigation.v5.utils.DistanceUtils)2 Date (java.util.Date)2 Ignore (org.junit.Ignore)2