Search in sources :

Example 6 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class NavigationRouteTest method addRouteOptionsIncludedInRequest.

@Test
public void addRouteOptionsIncludedInRequest() throws Exception {
    List<Point> coordinates = new ArrayList<>();
    coordinates.add(Point.fromLngLat(1.0, 2.0));
    coordinates.add(Point.fromLngLat(1.0, 5.0));
    RouteOptions routeOptions = RouteOptions.builder().accessToken(ACCESS_TOKEN).baseUrl("https://api-directions-traf.com").requestUuid("XYZ_UUID").alternatives(true).language(Locale.US.getLanguage()).profile(DirectionsCriteria.PROFILE_WALKING).coordinates(coordinates).voiceUnits(DirectionsCriteria.METRIC).user("example_user").build();
    NavigationRoute navigationRoute = NavigationRoute.builder().origin(coordinates.get(0)).destination(coordinates.get(1)).routeOptions(routeOptions).build();
    String request = navigationRoute.getCall().request().url().toString();
    assertThat(request, containsString("https://api-directions-traf.com"));
    assertThat(request, containsString("alternatives=true"));
    assertThat(request, containsString(ACCESS_TOKEN));
    assertThat(request, containsString("voice_units=metric"));
    assertThat(request, containsString("example_user"));
    assertThat(request, containsString("language=en"));
    assertThat(request, containsString("walking"));
}
Also used : ArrayList(java.util.ArrayList) Point(com.mapbox.geojson.Point) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RouteOptions(com.mapbox.api.directions.v5.models.RouteOptions) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 7 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method isUserOffRoute_AssertFalseTwoUpdatesAwayFromManeuverThenOneTowards.

@Test
public void isUserOffRoute_AssertFalseTwoUpdatesAwayFromManeuverThenOneTowards() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    List<Point> coordinates = lineString.coordinates();
    Location firstLocationUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstLocationUpdate, routeProgress, options);
    Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location secondLocationUpdate = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    boolean isUserOffRouteFirstTry = offRouteDetector.isUserOffRoute(secondLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteFirstTry);
    Point secondLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location thirdLocationUpdate = buildDefaultLocationUpdate(secondLastPointInCurrentStep.longitude(), secondLastPointInCurrentStep.latitude());
    boolean isUserOffRouteSecondTry = offRouteDetector.isUserOffRoute(thirdLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteSecondTry);
    Location fourthLocationUpdate = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    boolean isUserOffRouteThirdTry = offRouteDetector.isUserOffRoute(fourthLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteThirdTry);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) LegStep(com.mapbox.api.directions.v5.models.LegStep) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 8 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method isUserOffRoute_AssertTrueWhenOnRouteButMovingAwayFromManeuver.

@Test
public void isUserOffRoute_AssertTrueWhenOnRouteButMovingAwayFromManeuver() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    List<Point> coordinates = lineString.coordinates();
    Location firstLocationUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstLocationUpdate, routeProgress, options);
    Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location secondLocationUpdate = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    boolean isUserOffRouteFirstTry = offRouteDetector.isUserOffRoute(secondLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteFirstTry);
    Point secondLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location thirdLocationUpdate = buildDefaultLocationUpdate(secondLastPointInCurrentStep.longitude(), secondLastPointInCurrentStep.latitude());
    boolean isUserOffRouteSecondTry = offRouteDetector.isUserOffRoute(thirdLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteSecondTry);
    Point thirdLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location fourthLocationUpdate = buildDefaultLocationUpdate(thirdLastPointInCurrentStep.longitude(), thirdLastPointInCurrentStep.latitude());
    boolean isUserOffRouteThirdTry = offRouteDetector.isUserOffRoute(fourthLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteThirdTry);
    Point fourthLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location fifthLocationUpdate = buildDefaultLocationUpdate(fourthLastPointInCurrentStep.longitude(), fourthLastPointInCurrentStep.latitude());
    boolean isUserOffRouteFourthTry = offRouteDetector.isUserOffRoute(fifthLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteFourthTry);
    Point fifthLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location sixthLocationUpdate = buildDefaultLocationUpdate(fifthLastPointInCurrentStep.longitude(), fifthLastPointInCurrentStep.latitude());
    boolean isUserOffRouteFifthTry = offRouteDetector.isUserOffRoute(sixthLocationUpdate, routeProgress, options);
    assertTrue(isUserOffRouteFifthTry);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) LegStep(com.mapbox.api.directions.v5.models.LegStep) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 9 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method isUserOffRoute_AssertFalseWhenOnStep.

@Test
public void isUserOffRoute_AssertFalseWhenOnStep() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    Point stepManeuverPoint = routeProgress.directionsRoute().legs().get(0).steps().get(0).maneuver().location();
    Location firstUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstUpdate, routeProgress, options);
    Point offRoutePoint = buildPointAwayFromPoint(stepManeuverPoint, 10, 90);
    Location secondUpdate = buildDefaultLocationUpdate(offRoutePoint.longitude(), offRoutePoint.latitude());
    boolean isUserOffRoute = offRouteDetector.isUserOffRoute(secondUpdate, routeProgress, options);
    assertFalse(isUserOffRoute);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 10 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method isUserOffRoute_AssertTrueWhenTooFarFromStep.

@Test
public void isUserOffRoute_AssertTrueWhenTooFarFromStep() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    Point stepManeuverPoint = routeProgress.directionsRoute().legs().get(0).steps().get(0).maneuver().location();
    Location firstUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstUpdate, routeProgress, options);
    Point offRoutePoint = buildPointAwayFromPoint(stepManeuverPoint, 100, 90);
    Location secondUpdate = buildDefaultLocationUpdate(offRoutePoint.longitude(), offRoutePoint.latitude());
    boolean isUserOffRoute = offRouteDetector.isUserOffRoute(secondUpdate, routeProgress, options);
    assertTrue(isUserOffRoute);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

Point (com.mapbox.geojson.Point)72 Test (org.junit.Test)31 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)29 Location (android.location.Location)18 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)17 LineString (com.mapbox.geojson.LineString)15 ArrayList (java.util.ArrayList)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)9 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)7 Feature (com.mapbox.geojson.Feature)4 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)4 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)3 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteOptions (com.mapbox.api.directions.v5.models.RouteOptions)2 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)2 BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)2