summaryrefslogtreecommitdiff
path: root/src/positioning/qgeocoordinate.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-10-09 15:50:16 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-10-13 09:32:40 +0200
commiteebf55a6919dff9eec4dd8529223aae6f6d0f569 (patch)
tree91e6f31e2bf18941e07d183bb0efa603061a4272 /src/positioning/qgeocoordinate.cpp
parentbbb2aa81c4cb58cb29ab3b5146b9b5cb909cd1c9 (diff)
downloadqtlocation-eebf55a6919dff9eec4dd8529223aae6f6d0f569.tar.gz
Fix QGeoCoordinate::toString() when rounding long/lat corner cases
Change-Id: I14da28acbd124e07da42fbf5efc3a501267f86f3 Task-number: QTBUG-41739 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/positioning/qgeocoordinate.cpp')
-rw-r--r--src/positioning/qgeocoordinate.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp
index ceb23cd3..e2a77bfd 100644
--- a/src/positioning/qgeocoordinate.cpp
+++ b/src/positioning/qgeocoordinate.cpp
@@ -502,6 +502,22 @@ QString QGeoCoordinate::toString(CoordinateFormat format) const
case DegreesMinutesWithHemisphere: {
double latMin = (absLat - int(absLat)) * 60;
double lngMin = (absLng - int(absLng)) * 60;
+
+ if (qRound(latMin) >= 60) {
+ absLat++;
+ latMin = qAbs(latMin - 60.0f);
+ //avoid invalid latitude due to latMin rounding below
+ if (qRound(absLat) >= 90)
+ latMin = 0.0f;
+ }
+ if (qRound(lngMin) >= 60) {
+ absLng++;
+ lngMin = qAbs(lngMin - 60.0f);
+ // avoid invalid longitude due to lngMin rounding below
+ if (qRound(absLng) >= 180)
+ lngMin = 0.0f;
+ }
+
latStr = QString::fromLatin1("%1%2 %3'")
.arg(QString::number(int(absLat)))
.arg(symbol)
@@ -519,6 +535,31 @@ QString QGeoCoordinate::toString(CoordinateFormat format) const
double latSec = (latMin - int(latMin)) * 60;
double lngSec = (lngMin - int(lngMin)) * 60;
+ // overflow to full minutes
+ if (qRound(latSec) >= 60) {
+ latMin++;
+ latSec = qAbs(latSec - 60.0f);
+ // overflow to full degrees
+ if (qRound(latMin) >= 60) {
+ absLat++;
+ latMin = qAbs(latMin - 60.0f);
+ // avoid invalid latitude due to latSec rounding below
+ if (qRound(absLat) >= 90)
+ latSec = 0.0f;
+ }
+ }
+ if (qRound(lngSec) >= 60) {
+ lngMin++;
+ lngSec = qAbs(lngSec - 60.0f);
+ if (qRound(lngMin) >= 60) {
+ absLng++;
+ lngMin = qAbs(lngMin - 60.0f);
+ // avoid invalid longitude due to lngSec rounding below
+ if (qRound(absLng) >= 180)
+ lngSec = 0.0f;
+ }
+ }
+
latStr = QString::fromLatin1("%1%2 %3' %4\"")
.arg(QString::number(int(absLat)))
.arg(symbol)