Skip to content

Commit

Permalink
Fix route requests that include waypoint names
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Sep 5, 2018
1 parent c0db742 commit 43075ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private NavigationRoute.Builder buildRequestFromLocation(Location location, Rout
}
addDestination(remainingWaypoints, builder);
addWaypoints(remainingWaypoints, builder);
addWaypointNames(progress, builder);
return builder;
}

Expand All @@ -114,6 +115,13 @@ private void addWaypoints(List<Point> remainingCoordinates, NavigationRoute.Buil
}
}

private void addWaypointNames(RouteProgress progress, NavigationRoute.Builder builder) {
String[] remainingWaypointNames = routeUtils.calculateRemainingWaypointNames(progress);
if (remainingWaypointNames != null) {
builder.addWaypointNames(remainingWaypointNames);
}
}

private void executeRouteCall(NavigationRoute.Builder builder) {
if (builder != null) {
builder.accessToken(accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.api.directions.v5.models.LegStep;
import com.mapbox.api.directions.v5.models.RouteLeg;
import com.mapbox.api.directions.v5.models.RouteOptions;
import com.mapbox.api.directions.v5.models.VoiceInstructions;
import com.mapbox.core.utils.TextUtils;
import com.mapbox.geojson.Point;
import com.mapbox.services.android.navigation.v5.milestone.BannerInstructionMilestone;
import com.mapbox.services.android.navigation.v5.milestone.Milestone;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -30,8 +32,8 @@ public class RouteUtils {

private static final String FORCED_LOCATION = "Forced Location";
private static final int FIRST_COORDINATE = 0;
private static final int ZERO_INSTRUCTIONS = 0;
private static final int FIRST_INSTRUCTION = 0;
private static final String SEMICOLON = ";";
private static final Set<String> VALID_PROFILES = new HashSet<String>() {
{
add(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC);
Expand Down Expand Up @@ -136,6 +138,25 @@ public List<Point> calculateRemainingWaypoints(RouteProgress routeProgress) {
return coordinates;
}

/**
* Given a {@link RouteProgress}, this method will calculate the remaining waypoint names
* along the given route based on route option waypoint names and the progress remaining coordinates.
*
* @param routeProgress for route waypoint names and remaining coordinates
* @return String array of remaining waypoint names
* @since 0.19.0
*/
@Nullable
public String[] calculateRemainingWaypointNames(RouteProgress routeProgress) {
RouteOptions routeOptions = routeProgress.directionsRoute().routeOptions();
if (routeOptions == null || TextUtils.isEmpty(routeOptions.waypointNames())) {
return null;
}
String waypointNames = routeOptions.waypointNames();
String[] names = waypointNames.split(SEMICOLON);
return Arrays.copyOfRange(names, FIRST_COORDINATE, routeProgress.remainingWaypoints());
}

/**
* If navigation begins, a location update is sometimes needed to force a
* progress change update as soon as navigation is started.
Expand Down

0 comments on commit 43075ba

Please sign in to comment.