Nick
Nick

Reputation: 109

Get route points on the map

I'm using mapbox API and want to get direction from A to B with List<Point> which I can use to draw correct path on the map. But the problem is DirectionsResponse returns not enough points, see

enter image description here

part of line located on the water. Maybe in the MapboxDirections class or another one has step method with meters parameter, to get Point every 10m.

Here my current code:

MapboxDirections directions = MapboxDirections.builder()
                .accessToken(ACCESS_TOKEN)
                .profile(PROFILE_DRIVING)
                // Brooklyn, NY, USA
                .origin(Point.fromLngLat(-73.947803, 40.677790))
                // Upper West Side, NY, USA
                .destination(Point.fromLngLat(-73.971609, 40.784246))
                .build();

        Response<DirectionsResponse> response = directions.executeCall();
        DirectionsResponse directionsResponse = response.body();
        for (DirectionsRoute route : directionsResponse.routes()) {
            List<Point> decode = PolylineUtils.decode(route.geometry(), PRECISION_6);
            // I need here more points
            for (Point point : decode) {
                System.out.println(point.latitude() + ", " + point.longitude());
            }
        }

Upvotes: 0

Views: 176

Answers (1)

BDD
BDD

Reputation: 725

Try adding .overview(DirectionsCriteria.OVERVIEW_FULL) to get all the points like in this example

Your code would look something like this:

MapboxDirections directions = MapboxDirections.builder()
                .accessToken(ACCESS_TOKEN)
                .profile(PROFILE_DRIVING)
                .overview(DirectionsCriteria.OVERVIEW_FULL) /** New line **/
                // Brooklyn, NY, USA
                .origin(Point.fromLngLat(-73.947803, 40.677790))
                // Upper West Side, NY, USA
                .destination(Point.fromLngLat(-73.971609, 40.784246))
                .build();

Upvotes: 2

Related Questions