@@ -115,6 +115,8 @@ public void cancelCall() {
115115 */
116116 public static final class Builder {
117117
118+ private static final String SEMICOLON = ";" ;
119+ private static final String COMMA = "," ;
118120 private final MapboxDirections .Builder directionsBuilder ;
119121
120122 /**
@@ -481,6 +483,26 @@ public Builder addWaypointNames(@Nullable String... waypointNames) {
481483 return this ;
482484 }
483485
486+ /**
487+ * A list of coordinate pairs used to specify drop-off
488+ * locations that are distinct from the locations specified in coordinates.
489+ * If this parameter is provided, the Directions API will compute the side of the street,
490+ * <tt>left</tt> or <tt>right</tt>, for each target based on the <tt>waypoint_targets</tt>
491+ * and the driving direction.
492+ * The <tt>maneuver.modifier</tt>, banner and voice instructions will be updated with the computed
493+ * side of street. The number of waypoint targets must be the same as the number of coordinates,
494+ * but you can skip a coordinate pair and show its position in the list adding <tt>null</tt>.
495+ * Must be used with <tt>steps=true</tt>.
496+ *
497+ * @param waypointTargets {@link Point} coordinates for drop-off locations
498+ * @return this builder for chaining options together
499+ * @since 0.26.0
500+ */
501+ public Builder addWaypointTargets (@ Nullable Point ... waypointTargets ) {
502+ directionsBuilder .addWaypointTargets (waypointTargets );
503+ return this ;
504+ }
505+
484506 /**
485507 * Optionally create a {@link Builder} based on all variables
486508 * from given {@link RouteOptions}.
@@ -532,15 +554,21 @@ public Builder routeOptions(RouteOptions options) {
532554 }
533555
534556 if (!TextUtils .isEmpty (options .approaches ())) {
535- String [] approaches = options .approaches ().split (";" );
557+ String [] approaches = options .approaches ().split (SEMICOLON );
536558 directionsBuilder .addApproaches (approaches );
537559 }
538560
539561 if (!TextUtils .isEmpty (options .waypointNames ())) {
540- String [] waypointNames = options .waypointNames ().split (";" );
562+ String [] waypointNames = options .waypointNames ().split (SEMICOLON );
541563 directionsBuilder .addWaypointNames (waypointNames );
542564 }
543565
566+ String waypointTargets = options .waypointTargets ();
567+ if (!TextUtils .isEmpty (waypointTargets )) {
568+ Point [] splittedWaypointTargets = parseWaypointTargets (waypointTargets );
569+ directionsBuilder .addWaypointTargets (splittedWaypointTargets );
570+ }
571+
544572 return this ;
545573 }
546574
@@ -563,5 +591,23 @@ public NavigationRoute build() {
563591 .roundaboutExits (true );
564592 return new NavigationRoute (directionsBuilder .build ());
565593 }
594+
595+ @ NonNull
596+ private Point [] parseWaypointTargets (String waypointTargets ) {
597+ String [] splittedWaypointTargets = waypointTargets .split (SEMICOLON );
598+ Point [] waypoints = new Point [splittedWaypointTargets .length ];
599+ int index = 0 ;
600+ for (String waypointTarget : splittedWaypointTargets ) {
601+ String [] point = waypointTarget .split (COMMA );
602+ if (waypointTarget .isEmpty ()) {
603+ waypoints [index ++] = null ;
604+ } else {
605+ double longitude = Double .valueOf (point [0 ]);
606+ double latitude = Double .valueOf (point [0 ]);
607+ waypoints [index ++] = Point .fromLngLat (longitude , latitude );
608+ }
609+ }
610+ return waypoints ;
611+ }
566612 }
567613}
0 commit comments