From d0a274d877631cda3af79608fc6663317e8d502b Mon Sep 17 00:00:00 2001 From: max-klaus Date: Sat, 22 Aug 2020 16:26:28 +0300 Subject: [PATCH] Fix distance in toolbar --- .../measurementtool/MeasurementEditingContext.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 8c8d63d0e3..b3d71fd290 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -210,8 +210,17 @@ public class MeasurementEditingContext { public double getRouteDistance() { double distance = 0; - for (RoadSegmentData data : roadSegmentData.values()) { - distance += data.getDistance(); + for (List points : Arrays.asList(before.points, after.points)) { + for (int i = 0; i < points.size() - 1; i++) { + Pair pair = new Pair<>(points.get(i), points.get(i + 1)); + RoadSegmentData data = this.roadSegmentData.get(pair); + if (data == null) { + distance += MapUtils.getDistance(pair.first.getLatitude(), pair.first.getLongitude(), + pair.second.getLatitude(), pair.second.getLongitude()); + } else { + distance += data.getDistance(); + } + } } return distance; }