Skip to content

Commit 3fe0caa

Browse files
author
Cameron Mace
authored
support for multiple legs (#496)
* support for multiple legs * support for multiple legs added * nit empty line * added comment explaining the list adding
1 parent a4136c7 commit 3fe0caa

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

mapbox/libandroid-services/src/main/java/com/mapbox/services/android/location/MockLocationEngine.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,21 +301,25 @@ public void setRoute(DirectionsRoute route) {
301301
*/
302302
private void calculateStepPoints() {
303303
LineString line = LineString.fromPolyline(
304-
route.getLegs().get(currentLeg)
305-
.getSteps().get(currentStep).getGeometry(), Constants.PRECISION_6);
304+
route.getLegs().get(currentLeg).getSteps().get(currentStep).getGeometry(), Constants.PRECISION_6);
306305

307-
if (currentStep < route.getLegs().get(currentLeg).getSteps().size() - 1) {
308-
currentStep++;
309-
} else if (currentLeg < route.getLegs().size() - 1) {
310-
currentLeg++;
311-
}
306+
increaseIndex();
312307

313308
sliceRoute(line, distance);
314309
if (noisyGps) {
315310
addNoiseToRoute(distance);
316311
}
317312
}
318313

314+
private void increaseIndex() {
315+
if (currentStep < route.getLegs().get(currentLeg).getSteps().size() - 1) {
316+
currentStep++;
317+
} else if (currentLeg < route.getLegs().size() - 1) {
318+
currentLeg++;
319+
currentStep = 0;
320+
}
321+
}
322+
319323
/**
320324
* Here we build the new mock {@link Location} object and fill in as much information we can calculate.
321325
*
@@ -353,7 +357,9 @@ private Location mockLocation(Position position) {
353357
private class LocationUpdateRunnable implements Runnable {
354358
@Override
355359
public void run() {
356-
if (positions.size() <= 5) {
360+
// Calculate the next steps points if the list becomes empty
361+
// so that the mock location continues along the route
362+
if (positions.size() <= 0) {
357363
calculateStepPoints();
358364
}
359365

0 commit comments

Comments
 (0)