0

I'm working with mapbox android, i'm trying to add multiple waypoints between origin and destination.but after adding one waypoint when it's adding another one this gives the exception " Too many coordinate the s; maximum number of coordinates is 3."

I just want to add multiple waypoint between two point and draw route over those line in mapbox android.

[pastbin link] : https://paste.ubuntu.com/p/PKMQzFyzVb/

My Route Draw Function -->

{
    private void getRouteWithWaypoint(Point origin, Point destination, List<Point> wayPoints) {
        assert Mapbox.getAccessToken() != null;
        NavigationRoute.Builder builder = NavigationRoute.builder(getActivity())
                .accessToken(Mapbox.getAccessToken())
                .origin(origin)
                .destination(destination);
        if (wayPoints != null) {
            for (Point point : wayPoints) {
                builder.addWaypoint(point);
            }
        }
        builder.build().getRoute(new Callback<DirectionsResponse>() {
            @Override
            public void onResponse(@NonNull Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
                Log.e(TAG, "Response code: " + response.code());
                if (response.body() == null) {
                    Log.e(TAG, "No routes found, make sure you set the right user and access token.");
                    return;
                } else if (response.body().routes().size() < 1) {
                    Log.e(TAG, "No routes found");
                    return;
                }
                currentRoute = response.body().routes().get(0);
                if (navigationMapRoute != null) {
                    navigationMapRoute.removeRoute();
                } else {
                    navigationMapRoute = new NavigationMapRoute(null, mapView, map, R.style.NavigationMapRoute);
                }
                navigationMapRoute.addRoute(currentRoute);

            }

            @SuppressLint("TimberArgCount")
            @Override
            public void onFailure(Call<DirectionsResponse> call, Throwable t) {
                Timber.e(t, "Error: %s");
            }
        });

    }}
Alik
  • 1
  • 1

2 Answers2

0

Draw root on Mapbox map, copied the below code from Mapbox documentation.

private void getRoute(Point origin, Point destination) {
  NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .build()
    .getRoute(new Callback<DirectionsResponse>() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        // You can get the generic HTTP info about the response
        Log.d(TAG, "Response code: " + response.code());
        if (response.body() == null) {
          Log.e(TAG, "No routes found, make sure you set the right user and access token.");
          return;
        } else if (response.body().routes().size() < 1) {
          Log.e(TAG, "No routes found");
          return;
        }

        currentRoute = response.body().routes().get(0);

        // Draw the route on the map
        if (navigationMapRoute != null) {
          navigationMapRoute.removeRoute();
        } else {
          navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, R.style.NavigationMapRoute);
        }
        navigationMapRoute.addRoute(currentRoute);
      }

      @Override
      public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
        Log.e(TAG, "Error: " + throwable.getMessage());
      }
    });
}

for more detail follow the link https://www.mapbox.com/help/android-navigation-sdk/#calculate-and-draw-route

Shamsul
  • 435
  • 6
  • 15
  • Unfortunately, I'm not looking for this, I need to draw the route with multiple waypoints, I tried it with there documentation, but can't add more than one waypoint on it. – Alik Nov 13 '18 at 04:45
0

The default profile for requesting routes is DirectionsCriteria.ProfileCriteria.PROFILE_DRIVING_TRAFFIC

This profile allows only 1 waypoint between the origin and the destination. If you want to use more than 1 waypoint, just use PROFILE_DRIVING instead (this allows up to 25 waypoints I think).

Like this:

 NavigationRoute.Builder builder = NavigationRoute.builder(getActivity())
            .accessToken(Mapbox.getAccessToken())
            .origin(origin)
            .destination(destination)
            .profile(DirectionsCriteria.ProfileCriteria.PROFILE_DRIVING);
    if (wayPoints != null) {
        for (Point point : wayPoints) {
            builder.addWaypoint(point);
        }
    }
David Wasser
  • 93,459
  • 16
  • 209
  • 274