More precision with QGeocoordinate
-
Hello, I'm seeing the class QGeoCoordinate.
To test it I wrote a very simple code#include <QCoreApplication> #include <QDebug> #include <QGeoCoordinate> int main (int argc, char * argv []) { QCoreApplication a (argc, argv); QGeoCoordinate g; g.setLatitude (45.7293679); g.setLongitude (11.9152492); g.setAltitude (88.10); qDebug () << g.toString (QGeoCoordinate :: degrees); qDebug () << g.toString (QGeoCoordinate :: DegreesMinutesSecondsWithHemisphere); qDebug () << g.toString (QGeoCoordinate :: DegreesMinutesWithHemisphere); return a.exec (); }
the result is:
"45.72937°, 11.91525°, 88.1m" "45° 43' 45.7\" N, 11° 54' 54.9\" E, 88.1m" "45° 43.762' N, 11° 54.915' E, 88.1m"
I ask me if is possibile to have more precision.
For example, I've specified coordinates with 7 decimals, butqDebug () << g.toString (QGeoCoordinate :: degrees);
returns coordinates with 5 decimals.
Many thanks for your answer.
Stefano
-
@Stefanoxjx
this is just the default string formatting of this class.
You can easily format it to your needs for degrees.const int precision = 7; qDebug() << QString("%1°, %2°, %3m").arg( g.latitude(), 0, 'f', precision ).arg( g.longitude(), 0, 'f', precision ).arg( g.altitude(), 0, 'f', 2);
-
Hi raven-worx and thanks for your reply.
You've formatted output of QString, but if I would like to have more precision in coordinates conversion?
For example, the output of this line:qDebug() << g.toString(QGeoCoordinate::DegreesMinutesWithHemisphere);
is:
"45° 43.762' N, 11° 54.915' E, 88.1m"
but if I wanted to have:
"45° 43.762123' N, 11° 54.915123' E, 88.11m"
is possible?
Thansk.Stefano
-
@Stefanoxjx
same procedure, just some calculations needed.
I leave it up to you to check the calculations necessary in the source code. -
Many thanks for your help.
Stefano