Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Android Precise Location Issue
Qt 6.12 LTS is out! See what's new in the release blog

Qt Android Precise Location Issue

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
11 Posts 3 Posters 3.5k 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.
  • myzinskyM Offline
    myzinskyM Offline
    myzinsky
    wrote on 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?

    ekkescornerE MesrineM 2 Replies Last reply
    1
    • myzinskyM myzinsky

      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?

      ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on 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

      1 Reply Last reply
      0
      • myzinskyM myzinsky

        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?

        MesrineM Offline
        MesrineM Offline
        Mesrine
        wrote on last edited by Mesrine
        #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 :).

        ekkescornerE 1 Reply Last reply
        0
        • MesrineM Mesrine

          @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 :).

          ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote on last edited by ekkescorner
          #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

          MesrineM 1 Reply Last reply
          0
          • ekkescornerE ekkescorner

            @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

            MesrineM Offline
            MesrineM Offline
            Mesrine
            wrote on 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.

            myzinskyM 1 Reply Last reply
            0
            • MesrineM Mesrine

              @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.

              myzinskyM Offline
              myzinskyM Offline
              myzinsky
              wrote on 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 :-(

              ekkescornerE 1 Reply Last reply
              0
              • myzinskyM myzinsky

                @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 :-(

                ekkescornerE Offline
                ekkescornerE Offline
                ekkescorner
                Qt Champions 2016
                wrote on 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

                MesrineM 1 Reply Last reply
                0
                • ekkescornerE ekkescorner

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

                  MesrineM Offline
                  MesrineM Offline
                  Mesrine
                  wrote on last edited by Mesrine
                  #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.

                  myzinskyM 1 Reply Last reply
                  0
                  • MesrineM Mesrine

                    @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.

                    myzinskyM Offline
                    myzinskyM Offline
                    myzinsky
                    wrote on 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.

                    MesrineM 1 Reply Last reply
                    0
                    • myzinskyM myzinsky

                      @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.

                      MesrineM Offline
                      MesrineM Offline
                      Mesrine
                      wrote on 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.

                      myzinskyM 1 Reply Last reply
                      0
                      • MesrineM Mesrine

                        @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.

                        myzinskyM Offline
                        myzinskyM Offline
                        myzinsky
                        wrote on 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

                        • Login

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