Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class EndNavigationActivity extends AppCompatActivity implements OnNaviga
private FloatingActionButton launchNavigationFab;
private Point origin = Point.fromLngLat(-122.423579, 37.761689);
private Point pickup = Point.fromLngLat(-122.424467, 37.761027);
private Point middlePickup = Point.fromLngLat(-122.428604, 37.763559);
private Point destination = Point.fromLngLat(-122.426183, 37.760872);
private DirectionsRoute route;
private boolean paellaPickedUp = false;
Expand Down Expand Up @@ -115,7 +116,9 @@ private void fetchRoute() {
.accessToken(getString(R.string.mapbox_access_token))
.origin(origin)
.addWaypoint(pickup)
.addWaypoint(middlePickup)
.destination(destination)
.addWaypointIndices(0, 2, 3)
.alternatives(true)
.build();
builder.getRoute(this);
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {

version = [
mapboxMapSdk : '7.1.2',
mapboxSdkServices : '4.3.0',
mapboxSdkServices : '4.4.0',
mapboxEvents : '4.2.0',
mapboxNavigator : '4.0.0',
mapboxAnnotationPlugin : '0.5.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

Expand Down Expand Up @@ -94,7 +95,7 @@ public void getRoute(final Callback<DirectionsResponse> callback) {
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
elapsedTime.end();
callback.onResponse(call, response);
if (response.body().routes() != null && !response.body().routes().isEmpty()) {
if (response.body() != null && !response.body().routes().isEmpty()) {
navigationTelemetry.routeRetrievalEvent(elapsedTime,
response.body().routes().get(0).routeOptions().requestUuid());
}
Expand Down Expand Up @@ -495,6 +496,23 @@ public Builder addApproaches(String... approaches) {
return this;
}


/**
* Optionally, set which input coordinates should be treated as waypoints / separate legs.
* Note: coordinate indices not added here act as silent waypoints
* <p>
* Most useful in combination with <tt>steps=true</tt> and requests based on traces
* with high sample rates. Can be an index corresponding to any of the input coordinates,
* but must contain the first ( 0 ) and last coordinates' index separated by <tt>;</tt>.
*
* @param indices integer array of coordinate indices to be used as waypoints
* @return this builder for chaining options together
*/
public Builder addWaypointIndices(@Nullable @IntRange(from = 0) Integer... indices) {
directionsBuilder.addWaypointIndices(indices);
return this;
}

/**
* Custom names for waypoints used for the arrival instruction,
* each separated by <tt>;</tt>. Values can be any string and total number of all characters cannot
Expand Down Expand Up @@ -585,15 +603,21 @@ public Builder routeOptions(RouteOptions options) {
directionsBuilder.addApproaches(approaches);
}

String waypointIndices = options.waypointIndices();
if (!TextUtils.isEmpty(waypointIndices)) {
Integer[] splitWaypointIndices = parseWaypointIndices(waypointIndices);
directionsBuilder.addWaypointIndices(splitWaypointIndices);
}

if (!TextUtils.isEmpty(options.waypointNames())) {
String[] waypointNames = options.waypointNames().split(SEMICOLON);
directionsBuilder.addWaypointNames(waypointNames);
}

String waypointTargets = options.waypointTargets();
if (!TextUtils.isEmpty(waypointTargets)) {
Point[] splittedWaypointTargets = parseWaypointTargets(waypointTargets);
directionsBuilder.addWaypointTargets(splittedWaypointTargets);
Point[] splitWaypointTargets = parseWaypointTargets(waypointTargets);
directionsBuilder.addWaypointTargets(splitWaypointTargets);
}

return this;
Expand All @@ -619,12 +643,24 @@ public NavigationRoute build() {
return new NavigationRoute(directionsBuilder.build());
}

@NonNull
private Integer[] parseWaypointIndices(String waypointIndices) {
String[] splitWaypointIndices = waypointIndices.split(SEMICOLON);
Integer[] indices = new Integer[splitWaypointIndices.length];
int index = 0;
for (String waypointIndex : splitWaypointIndices) {
int parsedIndex = Integer.valueOf(waypointIndex);
indices[index++] = parsedIndex;
}
return indices;
}

@NonNull
private Point[] parseWaypointTargets(String waypointTargets) {
String[] splittedWaypointTargets = waypointTargets.split(SEMICOLON);
Point[] waypoints = new Point[splittedWaypointTargets.length];
String[] splitWaypointTargets = waypointTargets.split(SEMICOLON);
Point[] waypoints = new Point[splitWaypointTargets.length];
int index = 0;
for (String waypointTarget : splittedWaypointTargets) {
for (String waypointTarget : splitWaypointTargets) {
String[] point = waypointTarget.split(COMMA);
if (waypointTarget.isEmpty()) {
waypoints[index++] = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ public void addApproachesIncludedInRequest() {
containsString("curb"));
}

@Test
public void checksWaypointIndicesIncludedInRequest() {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
.accessToken(ACCESS_TOKEN)
.origin(Point.fromLngLat(1.0, 2.0))
.addWaypoint(Point.fromLngLat(1.0, 3.0))
.addWaypoint(Point.fromLngLat(1.0, 3.0))
.destination(Point.fromLngLat(1.0, 5.0))
.addWaypointIndices(0, 2, 3)
.build();

assertThat(navigationRoute.getCall().request().url().toString(),
containsString("waypoints"));
}

@Test
public void addWaypointNamesIncludedInRequest() {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
Expand Down Expand Up @@ -142,9 +157,10 @@ public void reverseOriginDestinationDoesntMessUpBearings() throws Exception {
}

@Test
public void addRouteOptionsIncludedInRequest() throws Exception {
public void addRouteOptionsIncludedInRequest() {
List<Point> coordinates = new ArrayList<>();
coordinates.add(Point.fromLngLat(1.0, 2.0));
coordinates.add(Point.fromLngLat(1.0, 3.0));
coordinates.add(Point.fromLngLat(1.0, 5.0));

RouteOptions routeOptions = RouteOptions.builder()
Expand All @@ -158,14 +174,16 @@ public void addRouteOptionsIncludedInRequest() throws Exception {
.voiceUnits(DirectionsCriteria.METRIC)
.user("example_user")
.geometries("mocked_geometries")
.approaches("curb;unrestricted")
.waypointNames("Origin;Destination")
.waypointTargets(";0.99,4.99")
.approaches("curb;;unrestricted")
.waypointNames("Origin;Pickup;Destination")
.waypointTargets(";;0.99,4.99")
.waypointIndices("0;2")
.build();

NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
.origin(coordinates.get(0))
.destination(coordinates.get(1))
.addWaypoint(coordinates.get(1))
.destination(coordinates.get(2))
.routeOptions(routeOptions)
.build();

Expand Down