From 39010f4e710df379547e217cb64bbee7f320eb4c Mon Sep 17 00:00:00 2001 From: danesfeder Date: Thu, 21 Jun 2018 14:29:52 -0400 Subject: [PATCH] Round distance remaining to show first instruction immediately --- .../services/android/navigation/v5/utils/RouteUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/utils/RouteUtils.java b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/utils/RouteUtils.java index ba7a8d4651e..c7ede0d428a 100644 --- a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/utils/RouteUtils.java +++ b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/utils/RouteUtils.java @@ -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 VALID_PROFILES = new HashSet() { { add(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC); @@ -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 instructions = new ArrayList<>(currentStep.bannerInstructions()); Iterator 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); } } @@ -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); } }