From a69d5773a63dbe5d6d758cea8eca2bf724e9d672 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 12 Oct 2017 00:26:31 -0700 Subject: [PATCH] altoslib: Allow gps time later than requested if it's first When generating a KML file, we want to position markers near the start of the flight section. This is done by looking for a GPS coordinate 'before' the starting point of the flight, which doesn't work well when the first GPS coordinate is later than that. Pick the first point after the chosen time if there isn't an earlier one. Signed-off-by: Keith Packard --- altoslib/AltosFlightSeries.java | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/altoslib/AltosFlightSeries.java b/altoslib/AltosFlightSeries.java index 02bf64ff..2eaf8033 100644 --- a/altoslib/AltosFlightSeries.java +++ b/altoslib/AltosFlightSeries.java @@ -489,13 +489,24 @@ public class AltosFlightSeries extends AltosDataListener { public ArrayList gps_series; public AltosGPS gps_before(double time) { - AltosGPS gps = null; - for (AltosGPSTimeValue gtv : gps_series) - if (gtv.time <= time) - gps = gtv.gps; - else - break; - return gps; + AltosGPSTimeValue nearest = null; + for (AltosGPSTimeValue gtv : gps_series) { + if (nearest == null) + nearest = gtv; + else { + if (gtv.time <= time) { + if (nearest.time <= time && gtv.time > nearest.time) + nearest = gtv; + } else { + if (nearest.time > time && gtv.time < nearest.time) + nearest = gtv; + } + } + } + if (nearest != null) + return nearest.gps; + else + return null; } public AltosTimeSeries sats_in_view; -- 2.30.2