Skip to content

Commit

Permalink
Round distance remaining to show first instruction immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jun 21, 2018
1 parent 0fec2f2 commit e424a48
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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 Set<String> VALID_PROFILES = new HashSet<String>() {
{
add(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC);
Expand Down Expand Up @@ -177,17 +178,18 @@ public boolean isValidRouteProfile(String routeProfile) {
@Nullable
public BannerInstructions findCurrentBannerInstructions(LegStep currentStep, double stepDistanceRemaining) {
if (isValidStep(currentStep) && hasInstructions(currentStep.bannerInstructions())) {
int roundedDistanceRemaining = (int) stepDistanceRemaining;
List<BannerInstructions> instructions = new ArrayList<>(currentStep.bannerInstructions());
Iterator<BannerInstructions> instructionsIterator = instructions.iterator();
while (instructionsIterator.hasNext()) {
BannerInstructions instruction = instructionsIterator.next();
double distanceAlongGeometry = instruction.distanceAlongGeometry();
if (distanceAlongGeometry < stepDistanceRemaining) {
if (distanceAlongGeometry < roundedDistanceRemaining) {
instructionsIterator.remove();
}
}
int instructionIndex = checkValidIndex(instructions);
if (instructions.size() > 0) {
if (instructions.size() > ZERO_INSTRUCTIONS) {
return instructions.get(instructionIndex);
}
}
Expand Down Expand Up @@ -238,7 +240,7 @@ public VoiceInstructions findCurrentVoiceInstructions(LegStep currentStep, doubl
}
}
int instructionIndex = checkValidIndex(instructions);
if (instructions.size() > 0) {
if (instructions.size() > ZERO_INSTRUCTIONS) {
return instructions.get(instructionIndex);
}
}
Expand Down

0 comments on commit e424a48

Please sign in to comment.