Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Android Precise Location Issue
Forum Updated to NodeBB v4.3 + New Features

Qt Android Precise Location Issue

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
11 Posts 3 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.
  • M Offline
    M Offline
    myzinsky
    wrote on 6 Jan 2024, 14:10 last edited by
    #1

    I implemented a class that gives me the GPS-Location for my app. Here a minimal example:

    rbManager::rbManager(QObject *parent)
        : QAbstractListModel(parent)
    {
        nm = nullptr;
        initialized = false;
    
        QLocationPermission locationPermission;
        locationPermission.setAccuracy(QLocationPermission::Precise);
    
        if(qApp->checkPermission(locationPermission) != Qt::PermissionStatus::Granted) {
            qApp->requestPermission(QLocationPermission{}, this, &rbManager::permissionUpdated);
        } else {
            qDebug() << "PERMISSION ALREADY GRANTED";
            init();
        }
    }
    
    void rbManager::permissionUpdated(const QPermission &permission) {
        if (permission.status() == Qt::PermissionStatus::Granted) {
            qDebug() << "PERMISSION GRANTED";
            init();
        } else {
            qDebug() << "PERMISSION NOT GRANTED";
        }
    }
    

    The init function does something with the gps coordinates. On iOS everything works like expected. However on Android it does not work!

    I did everything which was mentioned in the qt6 docs: https://doc.qt.io/qt-6/qlocationpermission.html

    I used QLocationPermission::Precise as you can see in my C++ code. And I put this

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    

    in my manifest.

    On the console I get this output:

    D libCloudLogOffline_arm64-v8a.so: INIT
    I qt.positioning.android: Unknown positioningMethod
    I qt.positioning.android: Unknown positioningMethod
    W qt.positioning.android: : Position data not available due to missing permission
    

    So what I'm doing wrong here?

    Edit: Also I should mention, that when the app is installed and started for the first time, I'm asked only for approximate location... Maybe there is a bug in Qt?

    E M 2 Replies Last reply 8 Jan 2024, 10:56
    1
    • M myzinsky
      6 Jan 2024, 14:10

      I implemented a class that gives me the GPS-Location for my app. Here a minimal example:

      rbManager::rbManager(QObject *parent)
          : QAbstractListModel(parent)
      {
          nm = nullptr;
          initialized = false;
      
          QLocationPermission locationPermission;
          locationPermission.setAccuracy(QLocationPermission::Precise);
      
          if(qApp->checkPermission(locationPermission) != Qt::PermissionStatus::Granted) {
              qApp->requestPermission(QLocationPermission{}, this, &rbManager::permissionUpdated);
          } else {
              qDebug() << "PERMISSION ALREADY GRANTED";
              init();
          }
      }
      
      void rbManager::permissionUpdated(const QPermission &permission) {
          if (permission.status() == Qt::PermissionStatus::Granted) {
              qDebug() << "PERMISSION GRANTED";
              init();
          } else {
              qDebug() << "PERMISSION NOT GRANTED";
          }
      }
      

      The init function does something with the gps coordinates. On iOS everything works like expected. However on Android it does not work!

      I did everything which was mentioned in the qt6 docs: https://doc.qt.io/qt-6/qlocationpermission.html

      I used QLocationPermission::Precise as you can see in my C++ code. And I put this

      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
      

      in my manifest.

      On the console I get this output:

      D libCloudLogOffline_arm64-v8a.so: INIT
      I qt.positioning.android: Unknown positioningMethod
      I qt.positioning.android: Unknown positioningMethod
      W qt.positioning.android: : Position data not available due to missing permission
      

      So what I'm doing wrong here?

      Edit: Also I should mention, that when the app is installed and started for the first time, I'm asked only for approximate location... Maybe there is a bug in Qt?

      E Offline
      E Offline
      ekkescorner
      Qt Champions 2016
      wrote on 8 Jan 2024, 10:56 last edited by
      #2

      @myzinsky have you tried to request per mission for Precise and Approximate location ?

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      1 Reply Last reply
      0
      • M myzinsky
        6 Jan 2024, 14:10

        I implemented a class that gives me the GPS-Location for my app. Here a minimal example:

        rbManager::rbManager(QObject *parent)
            : QAbstractListModel(parent)
        {
            nm = nullptr;
            initialized = false;
        
            QLocationPermission locationPermission;
            locationPermission.setAccuracy(QLocationPermission::Precise);
        
            if(qApp->checkPermission(locationPermission) != Qt::PermissionStatus::Granted) {
                qApp->requestPermission(QLocationPermission{}, this, &rbManager::permissionUpdated);
            } else {
                qDebug() << "PERMISSION ALREADY GRANTED";
                init();
            }
        }
        
        void rbManager::permissionUpdated(const QPermission &permission) {
            if (permission.status() == Qt::PermissionStatus::Granted) {
                qDebug() << "PERMISSION GRANTED";
                init();
            } else {
                qDebug() << "PERMISSION NOT GRANTED";
            }
        }
        

        The init function does something with the gps coordinates. On iOS everything works like expected. However on Android it does not work!

        I did everything which was mentioned in the qt6 docs: https://doc.qt.io/qt-6/qlocationpermission.html

        I used QLocationPermission::Precise as you can see in my C++ code. And I put this

        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        

        in my manifest.

        On the console I get this output:

        D libCloudLogOffline_arm64-v8a.so: INIT
        I qt.positioning.android: Unknown positioningMethod
        I qt.positioning.android: Unknown positioningMethod
        W qt.positioning.android: : Position data not available due to missing permission
        

        So what I'm doing wrong here?

        Edit: Also I should mention, that when the app is installed and started for the first time, I'm asked only for approximate location... Maybe there is a bug in Qt?

        M Offline
        M Offline
        Mesrine
        wrote on 8 Jan 2024, 14:07 last edited by Mesrine 1 Aug 2024, 17:26
        #3

        @myzinsky
        I am getting the same error when getting Precise location.
        But if use Approximate it works.

        Edit: Checking Precise location permission also works.

        The error: Position data not available due to missing permission
        was due to using an active qml PositionSource without granting the permissions.
        I think this could change in the next run :).

        E 1 Reply Last reply 8 Jan 2024, 14:15
        0
        • M Mesrine
          8 Jan 2024, 14:07

          @myzinsky
          I am getting the same error when getting Precise location.
          But if use Approximate it works.

          Edit: Checking Precise location permission also works.

          The error: Position data not available due to missing permission
          was due to using an active qml PositionSource without granting the permissions.
          I think this could change in the next run :).

          E Offline
          E Offline
          ekkescorner
          Qt Champions 2016
          wrote on 8 Jan 2024, 14:15 last edited by ekkescorner 1 Aug 2024, 14:24
          #4

          @Mesrine both together don't work ? I mean: at first request Approximate, then Precise
          or what happens with both in Manifest and then request only Precise

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.8 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          M 1 Reply Last reply 8 Jan 2024, 17:31
          0
          • E ekkescorner
            8 Jan 2024, 14:15

            @Mesrine both together don't work ? I mean: at first request Approximate, then Precise
            or what happens with both in Manifest and then request only Precise

            M Offline
            M Offline
            Mesrine
            wrote on 8 Jan 2024, 17:31 last edited by
            #5

            @ekkescorner

            Now it is working asking for Precise location.
            I tried asking first Aproximate and then Precise but I think once you ask for Aproximate, asking(qApp->checkPermission(lPermission)) later for Precise will give Qt::PermissionStatus::Denied

            I have edited my previous comment.

            M 1 Reply Last reply 11 Jan 2024, 20:27
            0
            • M Mesrine
              8 Jan 2024, 17:31

              @ekkescorner

              Now it is working asking for Precise location.
              I tried asking first Aproximate and then Precise but I think once you ask for Aproximate, asking(qApp->checkPermission(lPermission)) later for Precise will give Qt::PermissionStatus::Denied

              I have edited my previous comment.

              M Offline
              M Offline
              myzinsky
              wrote on 11 Jan 2024, 20:27 last edited by
              #6

              @Mesrine

              So now, I ask for approx. first and then for precise.

              I qt.positioning.android: Unknown positioningMethod
              I qt.positioning.android: Unknown positioningMethod
              W qt.positioning.android: : Position data not available due to missing permission
              

              still I get this warning, and I don't see the GPS coordinates dropping out as for iOS :-(

              E 1 Reply Last reply 12 Jan 2024, 08:57
              0
              • M myzinsky
                11 Jan 2024, 20:27

                @Mesrine

                So now, I ask for approx. first and then for precise.

                I qt.positioning.android: Unknown positioningMethod
                I qt.positioning.android: Unknown positioningMethod
                W qt.positioning.android: : Position data not available due to missing permission
                

                still I get this warning, and I don't see the GPS coordinates dropping out as for iOS :-(

                E Offline
                E Offline
                ekkescorner
                Qt Champions 2016
                wrote on 12 Jan 2024, 08:57 last edited by
                #7

                @myzinsky from my understanding @Mesrine now only asks for Precise and it's important to ask for permission before using PositionSource

                ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                5.15 --> 6.8 https://t1p.de/ekkeChecklist
                QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                M 1 Reply Last reply 12 Jan 2024, 12:50
                0
                • E ekkescorner
                  12 Jan 2024, 08:57

                  @myzinsky from my understanding @Mesrine now only asks for Precise and it's important to ask for permission before using PositionSource

                  M Offline
                  M Offline
                  Mesrine
                  wrote on 12 Jan 2024, 12:50 last edited by Mesrine 1 Dec 2024, 12:51
                  #8

                  @ekkescorner

                  Exactly. In my case the warning W qt.positioning.android: : Position data not available due to missing permission was because I had an active position source without having granted location permissions.

                  My recommendation is to ask for permission(approximate or precise) first and check that all the properties/bindings that need the coordinates work after the permission is granted.

                  I qt.positioning.android: Unknown positioningMethod i do not know where is coming.

                  M 1 Reply Last reply 12 Jan 2024, 21:45
                  0
                  • M Mesrine
                    12 Jan 2024, 12:50

                    @ekkescorner

                    Exactly. In my case the warning W qt.positioning.android: : Position data not available due to missing permission was because I had an active position source without having granted location permissions.

                    My recommendation is to ask for permission(approximate or precise) first and check that all the properties/bindings that need the coordinates work after the permission is granted.

                    I qt.positioning.android: Unknown positioningMethod i do not know where is coming.

                    M Offline
                    M Offline
                    myzinsky
                    wrote on 12 Jan 2024, 21:45 last edited by
                    #9

                    @Mesrine @ekkescorner

                    But I think that's what im doing, I check first of all for all permissions and then I initialize positioning with my init() method.

                    Side note: When I ask for the permissions already at app start, in the constructor of my class, the app crashes because I think the QML cannot be loaded. Therefore I call the checkPermissions function before I want to get GPS coordinates.

                    You can see my code here:

                    1st: QML call: https://github.com/myzinsky/cloudLogOffline/blob/d374acba334ff6cb33fb57bf7ef9d94f2dcb84b5/qml/SettingsView.qml#L197
                    2nd: C++ processing: https://github.com/myzinsky/cloudLogOffline/blob/d374acba334ff6cb33fb57bf7ef9d94f2dcb84b5/src/repeatermodel.cpp#L51

                    That is the output:

                    D libCloudLogOffline_arm64-v8a.so: PRECISE PERMISSION GRANTED
                    D libCloudLogOffline_arm64-v8a.so: INIT
                    I qt.positioning.android: Unknown positioningMethod
                    I qt.positioning.android: Unknown positioningMethod
                    W qt.positioning.android: : Position data not available due to missing permission
                    

                    So permission was granted and I don't get coordinates. Although I do it in the order that you propose.

                    M 1 Reply Last reply 13 Jan 2024, 07:45
                    0
                    • M myzinsky
                      12 Jan 2024, 21:45

                      @Mesrine @ekkescorner

                      But I think that's what im doing, I check first of all for all permissions and then I initialize positioning with my init() method.

                      Side note: When I ask for the permissions already at app start, in the constructor of my class, the app crashes because I think the QML cannot be loaded. Therefore I call the checkPermissions function before I want to get GPS coordinates.

                      You can see my code here:

                      1st: QML call: https://github.com/myzinsky/cloudLogOffline/blob/d374acba334ff6cb33fb57bf7ef9d94f2dcb84b5/qml/SettingsView.qml#L197
                      2nd: C++ processing: https://github.com/myzinsky/cloudLogOffline/blob/d374acba334ff6cb33fb57bf7ef9d94f2dcb84b5/src/repeatermodel.cpp#L51

                      That is the output:

                      D libCloudLogOffline_arm64-v8a.so: PRECISE PERMISSION GRANTED
                      D libCloudLogOffline_arm64-v8a.so: INIT
                      I qt.positioning.android: Unknown positioningMethod
                      I qt.positioning.android: Unknown positioningMethod
                      W qt.positioning.android: : Position data not available due to missing permission
                      

                      So permission was granted and I don't get coordinates. Although I do it in the order that you propose.

                      M Offline
                      M Offline
                      Mesrine
                      wrote on 13 Jan 2024, 07:45 last edited by Mesrine
                      #10

                      @myzinsky

                      I think this
                      qApp->requestPermission(QLocationPermission{}, this, &rbManager::precisePermissionUpdated);
                      should be
                      qApp->requestPermission(preciselocationPermission, this, &rbManager::precisePermissionUpdated);
                      With this, you will be asking for precise location permission.
                      Also
                      qApp->requestPermission(QLocationPermission{}, this, &rbManager::precisePermissionUpdated);

                      execute
                      void rbManager::precisePermissionUpdated(const QPermission &permission)
                      But I am not sure about the function arguments const QPermission &permission .
                      Normally what I do is to check for permission again after
                      qApp->requestPermission
                      As explained here.
                      This is how I do it here
                      Sorry, I did not notice this before on the post.

                      M 1 Reply Last reply 13 Jan 2024, 20:22
                      0
                      • M Mesrine
                        13 Jan 2024, 07:45

                        @myzinsky

                        I think this
                        qApp->requestPermission(QLocationPermission{}, this, &rbManager::precisePermissionUpdated);
                        should be
                        qApp->requestPermission(preciselocationPermission, this, &rbManager::precisePermissionUpdated);
                        With this, you will be asking for precise location permission.
                        Also
                        qApp->requestPermission(QLocationPermission{}, this, &rbManager::precisePermissionUpdated);

                        execute
                        void rbManager::precisePermissionUpdated(const QPermission &permission)
                        But I am not sure about the function arguments const QPermission &permission .
                        Normally what I do is to check for permission again after
                        qApp->requestPermission
                        As explained here.
                        This is how I do it here
                        Sorry, I did not notice this before on the post.

                        M Offline
                        M Offline
                        myzinsky
                        wrote on 13 Jan 2024, 20:22 last edited by
                        #11

                        @Mesrine Okay, that was dumb :-D just a copy-paste issue ... Thanks anyway for the help! Now it works.

                        1 Reply Last reply
                        0

                        1/11

                        6 Jan 2024, 14:10

                        • Login

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