diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index 6448cd67a1..457fbe856b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -999,6 +999,7 @@ public class TransportRoutePlanner { List> sortedSegments = new ArrayList>(); if(firstSegment != null) { sortedSegments.add(firstSegment); + mergedSegments.remove(firstSegment); while(!mergedSegments.isEmpty()) { List last = sortedSegments.get(sortedSegments.size() - 1); List add = findAndDeleteMinDistance(last.get(last.size() - 1).getLocation(), mergedSegments, true); @@ -1007,6 +1008,7 @@ public class TransportRoutePlanner { } else if(lastSegment != null) { sortedSegments.add(lastSegment); + mergedSegments.remove(lastSegment); while(!mergedSegments.isEmpty()) { List first = sortedSegments.get(0); List add = findAndDeleteMinDistance(first.get(0).getLocation(), mergedSegments, false); @@ -1059,6 +1061,7 @@ public class TransportRoutePlanner { while (it.hasNext()) { List segmentToMerge = it.next(); merged = tryToMerge(firstSegment, segmentToMerge); + if (merged) { it.remove(); break;