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