use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationEngine method handleRequest.
/**
* Takes a new location model and runs all related engine checks against it
* (off-route, milestones, snapped location, and faster-route).
* <p>
* After running through the engines, all data is submitted to {@link NavigationService} via
* {@link NavigationEngine.Callback}.
*
* @param newLocationModel hold location, navigation (with options), and distances away from maneuver
*/
private void handleRequest(final NewLocationModel newLocationModel) {
final MapboxNavigation mapboxNavigation = newLocationModel.mapboxNavigation();
boolean snapToRouteEnabled = mapboxNavigation.options().snapToRoute();
final Location rawLocation = newLocationModel.location();
RouteProgress routeProgress = routeProcessor.buildNewRouteProgress(mapboxNavigation, rawLocation);
final boolean userOffRoute = isUserOffRoute(newLocationModel, routeProgress, routeProcessor);
routeProcessor.checkIncreaseIndex(mapboxNavigation);
RouteProgress previousRouteProgress = routeProcessor.getPreviousRouteProgress();
final List<Milestone> milestones = checkMilestones(previousRouteProgress, routeProgress, mapboxNavigation);
final Location location = routeProcessor.buildSnappedLocation(mapboxNavigation, snapToRouteEnabled, rawLocation, routeProgress, userOffRoute);
boolean fasterRouteEnabled = mapboxNavigation.options().enableFasterRouteDetection();
final boolean checkFasterRoute = fasterRouteEnabled && !userOffRoute && shouldCheckFasterRoute(newLocationModel, routeProgress);
final RouteProgress finalRouteProgress = routeProgress;
routeProcessor.setPreviousRouteProgress(finalRouteProgress);
responseHandler.post(new Runnable() {
@Override
public void run() {
callback.onNewRouteProgress(location, finalRouteProgress);
callback.onMilestoneTrigger(milestones, finalRouteProgress);
callback.onUserOffRoute(location, userOffRoute);
callback.onCheckFasterRoute(location, finalRouteProgress, checkFasterRoute);
}
});
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationEventDispatcher method onProgressChange.
void onProgressChange(Location location, RouteProgress routeProgress) {
if (metricEventListeners != null) {
// Update RouteProgress
metricEventListeners.onRouteProgressUpdate(routeProgress);
// Check if user has arrived and notify metric listener if so
if (RouteUtils.isArrivalEvent(routeProgress) && metricArrivalListener != null) {
metricArrivalListener.onArrival(location, routeProgress);
metricArrivalListener = null;
// If a this is the last leg, navigation is ending - remove listeners
if (RouteUtils.isLastLeg(routeProgress)) {
// Remove off route listeners
removeOffRouteListener(null);
// Remove metric listener
metricEventListeners = null;
}
}
}
for (ProgressChangeListener progressChangeListener : progressChangeListeners) {
progressChangeListener.onProgressChange(location, routeProgress);
}
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class NavigationMetricsWrapper method arriveEvent.
static void arriveEvent(SessionState sessionState, RouteProgress routeProgress, Location location) {
Hashtable<String, Object> arriveEvent = MapboxNavigationEvent.buildArriveEvent(sdkIdentifier, BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME, sessionState.sessionIdentifier(), location.getLatitude(), location.getLongitude(), sessionState.currentGeometry(), routeProgress.directionsRoute().routeOptions().profile(), routeProgress.directionsRoute().distance().intValue(), routeProgress.directionsRoute().duration().intValue(), sessionState.rerouteCount(), sessionState.startTimestamp(), (int) (sessionState.eventRouteDistanceCompleted() + routeProgress.distanceTraveled()), (int) routeProgress.distanceRemaining(), (int) routeProgress.durationRemaining(), sessionState.mockLocation(), sessionState.originalRequestIdentifier(), sessionState.requestIdentifier(), sessionState.originalGeometry(), sessionState.originalDistance(), sessionState.originalDuration(), null, sessionState.currentStepCount(), sessionState.originalStepCount());
MetricsRouteProgress metricsRouteProgress = new MetricsRouteProgress(routeProgress);
int absoluteDistance = DistanceUtils.calculateAbsoluteDistance(location, metricsRouteProgress);
MapboxTelemetry.getInstance().addPercentTimeInForeground(sessionState.percentInForeground(), arriveEvent);
MapboxTelemetry.getInstance().addPercentTimeInPortrait(sessionState.percentInPortrait(), arriveEvent);
MapboxTelemetry.getInstance().addAbsoluteDistanceToDestination(absoluteDistance, arriveEvent);
MapboxTelemetry.getInstance().addLocationEngineName(sessionState.locationEngineName(), arriveEvent);
MapboxTelemetry.getInstance().pushEvent(arriveEvent);
MapboxTelemetry.getInstance().flushEventsQueueImmediately(false);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class FasterRouteDetectorTest method obtainDefaultRouteProgress.
private RouteProgress obtainDefaultRouteProgress() throws Exception {
DirectionsRoute aRoute = obtainADirectionsRoute();
RouteProgress defaultRouteProgress = RouteProgress.builder().stepDistanceRemaining(100).legDistanceRemaining(700).distanceRemaining(1000).directionsRoute(aRoute).stepIndex(0).legIndex(0).build();
return defaultRouteProgress;
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.
the class FasterRouteDetectorTest method onFasterRouteResponse_isFasterRouteIsTrue.
@Test
public void onFasterRouteResponse_isFasterRouteIsTrue() throws Exception {
FasterRoute fasterRouteEngine = navigation.getFasterRouteEngine();
// Create current progress
RouteProgress currentProgress = obtainDefaultRouteProgress();
DirectionsRoute longerRoute = currentProgress.directionsRoute().toBuilder().duration(// Current route duration is very long
10000000d).build();
currentProgress = currentProgress.toBuilder().directionsRoute(longerRoute).build();
// Create new direction response
DirectionsResponse response = obtainADirectionsResponse();
boolean isFasterRoute = fasterRouteEngine.isFasterRoute(response, currentProgress);
assertTrue(isFasterRoute);
}
Aggregations