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
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 : '6.7.2',
mapboxSdkServices : '4.2.0',
mapboxSdkServices : '4.3.0',
mapboxEvents : '3.5.6',
mapboxNavigator : '3.4.11',
searchSdk : '0.1.0-SNAPSHOT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public void cancelCall() {
*/
public static final class Builder {

private static final String SEMICOLON = ";";
private static final String COMMA = ",";
private final MapboxDirections.Builder directionsBuilder;

/**
Expand Down Expand Up @@ -481,6 +483,26 @@ public Builder addWaypointNames(@Nullable String... waypointNames) {
return this;
}

/**
* A list of coordinate pairs used to specify drop-off
* locations that are distinct from the locations specified in coordinates.
* If this parameter is provided, the Directions API will compute the side of the street,
* <tt>left</tt> or <tt>right</tt>, for each target based on the <tt>waypoint_targets</tt>
* and the driving direction.
* The <tt>maneuver.modifier</tt>, banner and voice instructions will be updated with the computed
* side of street. The number of waypoint targets must be the same as the number of coordinates,
* but you can skip a coordinate pair and show its position in the list adding <tt>null</tt>.
* Must be used with <tt>steps=true</tt>.
*
* @param waypointTargets {@link Point} coordinates for drop-off locations
* @return this builder for chaining options together
* @since 0.26.0
*/
public Builder addWaypointTargets(@Nullable Point... waypointTargets) {
directionsBuilder.addWaypointTargets(waypointTargets);
return this;
}

/**
* Optionally create a {@link Builder} based on all variables
* from given {@link RouteOptions}.
Expand Down Expand Up @@ -532,15 +554,21 @@ public Builder routeOptions(RouteOptions options) {
}

if (!TextUtils.isEmpty(options.approaches())) {
String[] approaches = options.approaches().split(";");
String[] approaches = options.approaches().split(SEMICOLON);
directionsBuilder.addApproaches(approaches);
}

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

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

return this;
}

Expand All @@ -563,5 +591,23 @@ public NavigationRoute build() {
.roundaboutExits(true);
return new NavigationRoute(directionsBuilder.build());
}

@NonNull
private Point[] parseWaypointTargets(String waypointTargets) {
String[] splittedWaypointTargets = waypointTargets.split(SEMICOLON);
Point[] waypoints = new Point[splittedWaypointTargets.length];
int index = 0;
for (String waypointTarget : splittedWaypointTargets) {
String[] point = waypointTarget.split(COMMA);
if (waypointTarget.isEmpty()) {
waypoints[index++] = null;
} else {
double longitude = Double.valueOf(point[0]);
double latitude = Double.valueOf(point[0]);
waypoints[index++] = Point.fromLngLat(longitude, latitude);
}
}
return waypoints;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public void addWaypointNamesIncludedInRequest() {
containsString("Destination"));
}

@Test
public void addWaypointTargetsIncludedInRequest() {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
.accessToken(ACCESS_TOKEN)
.origin(Point.fromLngLat(1.0, 2.0))
.destination(Point.fromLngLat(1.0, 5.0))
.addWaypointTargets(null, Point.fromLngLat(0.99, 4.99))
.build();

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

@Test
public void addingPointAndBearingKeepsCorrectOrder() throws Exception {
NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
Expand Down Expand Up @@ -140,6 +153,7 @@ public void addRouteOptionsIncludedInRequest() throws Exception {
.geometries("mocked_geometries")
.approaches("curb;unrestricted")
.waypointNames("Origin;Destination")
.waypointTargets(";0.99,4.99")
.build();

NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
Expand All @@ -158,6 +172,7 @@ public void addRouteOptionsIncludedInRequest() throws Exception {
assertThat(request, containsString("walking"));
assertThat(request, containsString("curb"));
assertThat(request, containsString("Origin"));
assertThat(request, containsString("waypoint_targets"));
}

@Test
Expand Down