File tree Expand file tree Collapse file tree
mapbox/libandroid-services/src/main/java/com/mapbox/services/android/location Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments