Search in sources :

Example 61 with Point

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

the class RouteStepProgressTest method stepIntersections_includesAllStepIntersectionsAndNextManeuver.

@Test
public void stepIntersections_includesAllStepIntersectionsAndNextManeuver() throws Exception {
    RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(0).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(3).legIndex(0).build();
    RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
    int currentStepTotal = route.legs().get(0).steps().get(3).intersections().size();
    Point maneuverLocation = route.legs().get(0).steps().get(4).maneuver().location();
    assertEquals(currentStepTotal + 1, routeStepProgress.intersections().size());
    assertEquals(routeStepProgress.intersections().get(16).location().latitude(), maneuverLocation.latitude());
    assertEquals(routeStepProgress.intersections().get(16).location().longitude(), maneuverLocation.longitude());
}
Also used : Point(com.mapbox.geojson.Point) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 62 with Point

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

the class RouteStepProgressTest method getDurationRemaining_equalsCorrectValueAtIntervals.

@Test
public void getDurationRemaining_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    for (double i = 0; i < firstStep.distance(); i += stepSegments) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
        LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
        double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        double fractionRemaining = (firstStep.distance() - distance) / firstStep.distance();
        assertEquals((1.0 - fractionRemaining) * firstStep.duration(), routeStepProgress.durationRemaining(), BaseTest.LARGE_DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 63 with Point

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

the class SnapToRouteTest method getSnappedLocation_returnsProviderNameCorrectly.

@Test
@Ignore
public void getSnappedLocation_returnsProviderNameCorrectly() throws Exception {
    Snap snap = new SnapToRoute();
    Location location = new Location("test");
    List<Point> coordinates = PolylineUtils.decode(route.legs().get(0).steps().get(1).geometry(), Constants.PRECISION_6);
    Location snappedLocation = snap.getSnappedLocation(location, routeProgress, coordinates);
    assertTrue(snappedLocation.getProvider().equals("test-snapped"));
    assertTrue(location.getProvider().equals("test"));
}
Also used : Point(com.mapbox.geojson.Point) Location(android.location.Location) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 64 with Point

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

the class MockNavigationActivity method calculateRoute.

private void calculateRoute() {
    Location userLocation = mapboxMap.getMyLocation();
    if (userLocation == null) {
        Timber.d("calculateRoute: User location is null, therefore, origin can't be set.");
        return;
    }
    Point origin = Point.fromLngLat(userLocation.getLongitude(), userLocation.getLatitude());
    if (TurfMeasurement.distance(origin, destination, TurfConstants.UNIT_METERS) < 50) {
        startRouteButton.setVisibility(View.GONE);
        return;
    }
    final NavigationRoute.Builder navigationRouteBuilder = NavigationRoute.builder().accessToken(Mapbox.getAccessToken());
    navigationRouteBuilder.origin(origin);
    navigationRouteBuilder.destination(destination);
    if (waypoint != null) {
        navigationRouteBuilder.addWaypoint(waypoint);
    }
    navigationRouteBuilder.build().getRoute(new Callback<DirectionsResponse>() {

        @Override
        public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
            Timber.d("Url: %s", call.request().url().toString());
            if (response.body() != null) {
                if (!response.body().routes().isEmpty()) {
                    DirectionsRoute directionsRoute = response.body().routes().get(0);
                    MockNavigationActivity.this.route = directionsRoute;
                    navigationMapRoute.addRoutes(response.body().routes());
                }
            }
        }

        @Override
        public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
            Timber.e("onFailure: navigation.getRoute()", throwable);
        }
    });
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Point(com.mapbox.geojson.Point) NavigationRoute(com.mapbox.services.android.navigation.v5.navigation.NavigationRoute) Location(android.location.Location) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse)

Example 65 with Point

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

the class RerouteActivity method drawRoute.

private void drawRoute(DirectionsRoute route) {
    List<LatLng> points = new ArrayList<>();
    List<Point> coords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();
    for (Point point : coords) {
        points.add(new LatLng(point.latitude(), point.longitude()));
    }
    if (!points.isEmpty()) {
        if (polyline != null) {
            mapboxMap.removePolyline(polyline);
        }
        // Draw polyline on map
        polyline = mapboxMap.addPolyline(new PolylineOptions().addAll(points).color(Color.parseColor("#4264fb")).width(5));
    }
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Point(com.mapbox.geojson.Point) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

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