Navigation

    UBports Robot Logo

    UBports Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    QtWebEngine location access

    App Development
    2
    5
    187
    Loading More Posts
    • 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.
    • G
      Giiba last edited by

      Is there some trick to enabling location access for a webapp using the QtWebEngine?

      I'm just experimenting, using Sailbook as a template, with using google maps urls. The page loads and looks good but it simply doesn't have location access; there is no prompt from the webengine or OS, and the webpage just says it cannot determine location.

      I've adjusted the apparmor settings and added QtLocation and QtPositioning imports to the qml files. However all I can find is tutorials for using the mapping features of Qt and none that speak to finding current location.

      Anyone know of a tutorial or the right documentation?

      1 Reply Last reply Reply Quote 1
      • dobey
        dobey last edited by

        Is the code not using Morph.Web API to embed the engine? Although I think QtWebEngine itself should already be using the proper API for asking location access from Qt. Otherwise it may just be that you're missing the extra dialog implementation if you're embedding QtWebEngine itself instead of Morph.Web.

        I don't think you should need to use QtLocation or QtPositioning at all yourself, for a web page to get it. As long as the apparmor json is correct, it should work (and remember, if you change the apparmor, you need to change the version so the profile gets rebuilt when installing the app).

        G 1 Reply Last reply Reply Quote 1
        • G
          Giiba @dobey last edited by

          @dobey
          I didn't know about the version thing thx. However that's not the trouble it seems. Perhaps I should find a clean template to work from.

          1 Reply Last reply Reply Quote 0
          • G
            Giiba last edited by Giiba

            Looking closer there is no embedded webengine just imports in main.qml. But it does do:

            import Morph.Web 0.1
            import QtWebEngine 1.7
            

            so I have to admit I don't really know what is going on, I'm going to look for a clean template.

            1 Reply Last reply Reply Quote 0
            • G
              Giiba last edited by Giiba

              @dobey you were correct, the location call was just being ignored. Adding the necessary lines enabled access for the webapp. Thanks for the direction.

              I copied this from the Morph browser code:

              onFeaturePermissionRequested: {
                  switch(feature) {
                      case WebEngineView.Geolocation:
                      grantFeaturePermission(securityOrigin, feature, true);
                      break;
                  }
              }
              

              there is of course cases for other feature requests in the code I copied, and this just grants permission passing responsibility for approving the call to the OS. This does work around the issue where Morph asks permission each and everytime location is called, without the trouble of approving different sites as there is only one.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post