I am trying to display multiple routes in mapbox,I also enabled alternative to true still multiple routes are not displayed,would like to plot multiple routes on a map. However, this is not working.Is there any ways to display multiple routes in mapbox? I also attached my code below.
private void getRoute(MapboxMap mapboxMap, Point origin, Point destination) {
client = MapboxDirections.builder()
.origin(origin)
.destination(destination)
.overview(DirectionsCriteria.OVERVIEW_FULL)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.accessToken(getString(R.string.mapbox_access_token))
.alternatives(true)
.build();
client.enqueueCall(new Callback<DirectionsResponse>() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
// You can get the generic HTTP info about the response
Timber.d("Response code: " + response.code());
if (response.body() == null) {
Timber.e("No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().routes().size() < 1) {
Timber.e("No routes found");
return;
}
// Get the directions route
currentRoute = response.body().routes().get(0);
// Make a toast which displays the route's distance
Toast.makeText(DirectionsActivity.this, String.format(
"directions_activity_toast_message"), Toast.LENGTH_SHORT).show();
if (mapboxMap != null) {
mapboxMap.getStyle(new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
// Retrieve and update the source designated for showing the directions route
GeoJsonSource source = style.getSourceAs(ROUTE_SOURCE_ID);
// Create a LineString with the directions route's geometry and
// reset the GeoJSON source for the route LineLayer source
if (source != null) {
source.setGeoJson(LineString.fromPolyline(currentRoute.geometry(), PRECISION_6));
}
}
});
}
}