Search in sources :

Example 16 with RouteProgress

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);
        }
    });
}
Also used : Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location)

Example 17 with RouteProgress

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);
    }
}
Also used : ProgressChangeListener(com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener)

Example 18 with 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);
}
Also used : MetricsRouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)

Example 19 with RouteProgress

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;
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)

Example 20 with RouteProgress

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);
}
Also used : FasterRoute(com.mapbox.services.android.navigation.v5.route.FasterRoute) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

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