Mapbox-navigation-android: Error: Too many coordinates; maximum number of coordinates is 3

Created on 23 Jan 2019  路  2Comments  路  Source: mapbox/mapbox-navigation-android

This error appears when I try to build a NavigationRoute with more than 3 points :

public void buildJourney(Point origin, Point destination, ArrayList<Point> waypoints, Activity v, OnFinishedListener listener)
    {
        Log.i("BUILD JOURNEY", "LAUNCHED");
        NavigationRoute.Builder builder = NavigationRoute.builder(v)
                .accessToken(Mapbox.getAccessToken())
                .origin(origin)
                .destination(destination);

        Log.i("BUILD JOURNEY", "Builder created");
        for (Point waypoint : waypoints) {
            builder.addWaypoint(waypoint);
        }

        Log.i("BUILD JOURNEY", "Waypoint added");

        builder.build().getRoute(new Callback<DirectionsResponse>() {
            @Override
            public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> 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;
                }

                Log.i("BUILD JOURNEY", "Done");
                currentRoute = response.body().routes().get(0);
                listener.onRouteCreated(currentRoute);

            }

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

I'm using this versions :
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.2' implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.26.0'

I've tested all the Point on my wapoints list, they are good; and, on the documentation, they say that we can add 25 coordinates to the NavigationRoute builder.

The only answer I found was to disable the DirectionsCriteria.PROFILE_DRIVING_TRAFFIC parameter, but I didn't activate it, and I think this was an answer from an old version.

Would you know where this error is coming from?

Most helpful comment

Hey @Florent-Sebag 馃憢 DirectionsCriteria.PROFILE_DRIVING_TRAFFIC is the default in NavigationRoute and has a max of 3 coordinates:

https://github.com/mapbox/mapbox-navigation-android/blob/39d8cd01628e62e326bf5bf2be69f619281d8880/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationRoute.java#L69

If you'd like to use 25 coordinates, you can adjust the profile to PROFILE_DRIVING:

...
        Log.i("BUILD JOURNEY", "LAUNCHED");
        NavigationRoute.Builder builder = NavigationRoute.builder(v)
                .accessToken(Mapbox.getAccessToken())
                .profile(DirectionsCriteria.PROFILE_DRIVING)
                .origin(origin)
                .destination(destination);
...

Hope this helps, thanks for checking out the SDK!

All 2 comments

Hey @Florent-Sebag 馃憢 DirectionsCriteria.PROFILE_DRIVING_TRAFFIC is the default in NavigationRoute and has a max of 3 coordinates:

https://github.com/mapbox/mapbox-navigation-android/blob/39d8cd01628e62e326bf5bf2be69f619281d8880/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationRoute.java#L69

If you'd like to use 25 coordinates, you can adjust the profile to PROFILE_DRIVING:

...
        Log.i("BUILD JOURNEY", "LAUNCHED");
        NavigationRoute.Builder builder = NavigationRoute.builder(v)
                .accessToken(Mapbox.getAccessToken())
                .profile(DirectionsCriteria.PROFILE_DRIVING)
                .origin(origin)
                .destination(destination);
...

Hope this helps, thanks for checking out the SDK!

Changed to .profile(DirectionsCriteria.PROFILE_DRIVING) works for me as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jethromay picture jethromay  路  7Comments

haroonkhan9426 picture haroonkhan9426  路  8Comments

trinhvanminh2009 picture trinhvanminh2009  路  5Comments

zugaldia picture zugaldia  路  6Comments

diegolaballos picture diegolaballos  路  4Comments