From 5747ba1ca5ae48cc425536f4fd9a6d533ac61607 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 28 Oct 2022 15:34:01 +0000 Subject: [PATCH] LazMapViewer: Fix rounding error in GPS float to degrees-minutes-seconds conversion. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8582 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/lazmapviewer/source/mvengine.pas | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/lazmapviewer/source/mvengine.pas b/components/lazmapviewer/source/mvengine.pas index eab9a8dce..a740baf82 100644 --- a/components/lazmapviewer/source/mvengine.pas +++ b/components/lazmapviewer/source/mvengine.pas @@ -1295,7 +1295,12 @@ procedure SplitGps(AValue: Double; out ADegs, AMins: Double); begin AValue := abs(AValue); AMins := frac(AValue) * 60; - ADegs := trunc(AValue); + if abs(AMins - 60) < 1E-3 then + begin + AMins := 0; + ADegs := trunc(AValue) + 1; + end else + ADegs := trunc(AValue); end; procedure SplitGps(AValue: Double; out ADegs, AMins, ASecs: Double); @@ -1303,6 +1308,16 @@ begin SplitGps(AValue, ADegs, AMins); ASecs := frac(AMins) * 60; AMins := trunc(AMins); + if abs(ASecs - 60) < 1E-3 then + begin + ASecs := 0; + AMins := AMins + 1; + if abs(AMins - 60) < 1e-3 then + begin + AMins := 0; + ADegs := ADegs + 1; + end; + end; end; function GPSToDMS(Angle: Double): string;