Currently i am trying to create a navigation route in the android navigation SDK provided by mapbox. The problem starts when adding more than one waypoint to the query. (the query below returns a response and draws the route on the map)
NavigationRoute.builder()
.accessToken(Mapbox.getAccessToken())
.origin(start)
.destination(end)
.alternatives(false)
.build()
.getRoute(new Callback<DirectionsResponse>() {
@Override
public void onResponse(@NonNull Call<DirectionsResponse> call, @NonNull Response<DirectionsResponse> response) {
if (response.isSuccessful()) {
try {
assert response.body() != null;
routeodfgoh = response.body().routes().get(0);
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, map);
}
//how to draw the map think map matching is work
navigationMapRoute.addRoute(routeodfgoh);
} catch (Exception ex) {
Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_LONG);
}
}
}
@Override
public void onFailure(Call<DirectionsResponse> call, Throwable t) {
}
});
However, the application requires that some query's have more than one waypoint added. after lots of searching i found this mapbox-navigation-android add waypoints which lead to the code below. however, the query never returns a response.
NavigationRoute.Builder builder = NavigationRoute.builder()
.accessToken(Mapbox.getAccessToken())
.origin(start)
.destination(end);
for (Point waypoint : coords) {
builder.addWaypoint(waypoint);
}
builder.build()
.getRoute(new Callback<DirectionsResponse>() {
@Override
public void onResponse(@NonNull Call<DirectionsResponse> call, @NonNull Response<DirectionsResponse> response) {
if (response.isSuccessful()) {
try {
assert response.body() != null;
routeodfgoh = response.body().routes().get(0);
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, map);
}
//how to draw the map think map matching is work
navigationMapRoute.addRoute(routeodfgoh);
} catch (Exception ex) {
Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_LONG);
}
}
}
@Override
public void onFailure(Call<DirectionsResponse> call, Throwable t) {
}
});
any ideas as to why i don't get a response would be great.
The default profile is PROFILE_DRIVING_TRAFFIC
which has a limit of 3 coordinates. If you update this to PROFILE_DRIVING
, using .profile(DirectionsCriteria.PROFILE_DRIVING)
, that should solve the coordinate limit issue.