Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. More precision with QGeocoordinate
Qt 6.11 is out! See what's new in the release blog

More precision with QGeocoordinate

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on last edited by
    #1

    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, but

    qDebug () << g.toString (QGeoCoordinate :: degrees);
    

    returns coordinates with 5 decimals.

    Many thanks for your answer.

    Stefano

    raven-worxR 1 Reply Last reply
    0
    • S Stefanoxjx

      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, but

      qDebug () << g.toString (QGeoCoordinate :: degrees);
      

      returns coordinates with 5 decimals.

      Many thanks for your answer.

      Stefano

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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);
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Stefanoxjx
        wrote on last edited by
        #3

        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

        raven-worxR 1 Reply Last reply
        0
        • S Stefanoxjx

          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

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Stefanoxjx
          same procedure, just some calculations needed.
          I leave it up to you to check the calculations necessary in the source code.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • S Offline
            S Offline
            Stefanoxjx
            wrote on last edited by
            #5

            Many thanks for your help.

            Stefano

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved