From 3d4ad61f5ebe2207a347b708d9fb6a687ca6d639 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 30 Aug 2023 13:59:35 -0400 Subject: [PATCH] go through gps data backwards --- Program.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index be8ca54..0536da1 100644 --- a/Program.cs +++ b/Program.cs @@ -704,16 +704,18 @@ public class Game : GameWindow { allPhotos.Sort(ComparePhotosByDate); - // Fix up photos with missing GPS. + // Fix up photos with missing GPS. We start at the end and work our way + // backwards, because if one photo is missing GPS, it's probably because + // the camera was turned off for a while, and whichever photo *after* it + // has GPS data is probably more accurate. GpsInfo? lastGps = null; - foreach (Photo p in allPhotos) { - if (p.Gps != null) { - lastGps = p.Gps; - } + for (int i = allPhotos.Count - 1; i >= 0; i--) { + Photo p = allPhotos[i]; if (p.Gps == null) { - // FIXME: should we take from the photo immediately _before_, or after? Console.WriteLine("fixing GPS for " + p.Filename); p.Gps = lastGps; + } else { + lastGps = p.Gps; } } photos = allPhotos;