Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView and Google Maps JS API v3
QtWS25 Last Chance

QWebView and Google Maps JS API v3

Scheduled Pinned Locked Moved Qt WebKit
30 Posts 19 Posters 50.4k Views
  • 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.
  • P Offline
    P Offline
    pettel
    wrote on 3 Mar 2011, 11:14 last edited by
    #14

    I have the same issue (Qt 4.7.2). Adding "js?v=3.1&sensor=true" didn't do the trick for me.
    There is still no panning (left mousebutton) and zooming (mousewheel).

    I compiled Qt WebKit 2.1 from the repository (mingw, gcc 4.4.0), but the example browser crashes when i try to open a webpage.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ceptad
      wrote on 30 Apr 2011, 18:55 last edited by
      #15

      Hi,

      Today I have tired to use google maps with Qt and I'm having the same problems. Maybe somebody has more suggestions?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lowsnr
        wrote on 8 May 2011, 22:26 last edited by
        #16

        I've found a very hacky fix that can be used until Google and/or Nokia get with the program to either support WebKit or allow for the touch events to be disabled at runtime. Turns out, as part of the test that the Google code performs to determine whether the browser is touch enabled, it checks the User Agent for Chrome >= 5.0, so by changing the user agent to something like 'Chrome/1.0' the touch interface suppressed. I verified this with PySide 1.0.2 / Qt 4.7.2 / API 3.5.1 but it should in theory work with any Qt version.

        Example (PySide):
        @
        class ChromePage(QWebPage):
        def userAgentForUrl(self, url):
        return 'Chrome/1.0'

        _map = QWebView()
        _map.setPage(ChromePage())
        _map.load(QUrl('a/map/page.html'))
        @

        In case anyone's interested in the details, I de-minified Google's JS code and found this line:
        @
        ng = X[v] == 3 && X.b <= 5 ? !1 : lg(ontouchstart) && lg(ontouchmove) && lg(ontouchend)
        @
        which de-obsfucates roughly to:
        @
        useTouchUI = navigator.userAgent.toLowerCase() == 'chrome' && navigatorVersion <= 5 ? false : checkForEvent(ontouchstart) && checkForEvent(ontouchmove) && checkForEvent(ontouchend)
        @

        Interesting but I suppose unsurprising that Chrome is the one browser that Google checks for explicitly. I hope Google offers this as a selectable option (since it's the addition of a single line of code) but in the meantime, enjoy this fix.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          Yuvalal
          wrote on 21 May 2011, 10:32 last edited by
          #17

          Had to sign in to say thanks, you're a genius! I was struggling for weeks!

          here is the same trick in C++:

          @class myWebPage : public QWebPage
          {
          virtual QString userAgentForUrl(const QUrl& url) const {
          return "Chrome/1.0";
          }
          };

          ...
          map->setPage(new myWebPage());
          map->load(QUrl("a/map/page.html"));
          ...
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anisha Kaul
            wrote on 4 Jun 2011, 05:01 last edited by
            #18

            [quote author="Yuvalal" date="1305973922"]here is the same trick in C++:[/quote]
            Had to sign in to say thanks to you (for posting this in C++) and to @lowsnr.

            This worked flawlessly :hattip: to both of you (for posting the solution).

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gosztola.laszlo
              wrote on 10 Jun 2011, 18:44 last edited by
              #19

              I would like to say thank you, too
              Nice work!

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nasamit
                wrote on 27 Jun 2011, 09:09 last edited by
                #20

                Excellent!!! Great job!! It Works!!

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  ncsunickv
                  wrote on 27 Jun 2011, 19:50 last edited by
                  #21

                  Oustanding find!! I'm using webkit with a standard webview widget. Using the app args API works for this string, under this scheme (4.7.3):

                  QApplication app(argc, argv);
                  // Work around for QT Webkit/Google Maps V3 API to allow map panning via touch control
                  app.setApplicationName(QString("Chrome"));
                  app.setApplicationVersion(QString("1.0"));

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    outdoor_guy
                    wrote on 28 Jun 2011, 06:39 last edited by
                    #22

                    [quote author="Yuvalal" date="1305973922"]Had to sign in to say thanks, you're a genius! I was struggling for weeks!
                    [/quote]

                    I was struggeled also in that problem and have to say a lot of thanks for the C++ code. Now it works :-)

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rigelsg
                      wrote on 24 Nov 2011, 16:45 last edited by
                      #23

                      I have the same issue (Qt 4.7.2).
                      Adding “js?v=3.1&sensor=true” doesn't change the situation.
                      There is still no panning and zooming. I have tried this on my desktop and also on a linux board with touchscreen(the touchscreen works fine with Qt widgets ).

                      Any idea ?

                      1 Reply Last reply
                      0
                      • Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 24 Nov 2011, 16:54 last edited by
                        #24

                        [quote author="rigelsg" date="1322153106"]I have the same issue (Qt 4.7.2).
                        Any idea ?[/quote]
                        There were 3 or so working solutions given already. Read the thread please.

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rigelsg
                          wrote on 25 Nov 2011, 08:58 last edited by
                          #25

                          Excellent now it works :) , thank you.

                          Is there any way to save the maps on disk using QNetworkDiskCache ?

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            monst
                            wrote on 13 Dec 2011, 07:34 last edited by
                            #26

                            Thanks to lowsnr and Yuvalal :)
                            Your fix works for me too!

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              kur0nek0
                              wrote on 19 Dec 2011, 22:57 last edited by
                              #27

                              Thanks a lot to the two of you, I actaully just made an account to say thank you, you don't know how much time and effort you have saved me

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                justdad
                                wrote on 7 Mar 2012, 22:22 last edited by
                                #28

                                I can feel the pain above. I have been trying mouse dragging to work in a Webview with no luck. I have added my own buttons to my app and I can move the location but their operation needs a lot to be desiredc. Where can I get a project that has this working so I can use it as an example?

                                Ken

                                1 Reply Last reply
                                0
                                • J Offline
                                  J Offline
                                  JulsPower
                                  wrote on 18 Oct 2012, 16:39 last edited by
                                  #29

                                  http://qt-project.org/forums/viewthread/19887
                                  Working solution under windows
                                  I did try to build webkit but even if setting touch to 0 didn't work (got a fews tests to do on that option to confirm)

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    lowsnr
                                    wrote on 18 Nov 2012, 19:01 last edited by
                                    #30

                                    For what it's worth, my application using Qt 4.8.3 on Linux "just works" now when I delete the QWebPage::userAgentForUrl override. So my class now just has this:

                                    @
                                    QString ChromePage::userAgentForUrl(const QUrl & url) const
                                    {
                                    // Broken as of October 2012, but now default works?
                                    //return QString("Chrome/1.0");
                                    return QWebPage::userAgentForUrl(url);
                                    }
                                    @

                                    I am also specifying Maps API version 3.9 - I haven't played around with the newer versions, but it seems to work for me. I did dig into the 3.9 javascript, and the touch events check is now based on the operating system detected from the user agent rather than the browser type, so if things still aren't working for you, make sure your UA string reports "X11", "Windows" or "Macintosh" and it may fix things.

                                    ETA: this also works with the 3.exp version of Google Maps. If you're interested in seeing the code in context, here are links to the viewer class and the web page on GitHub that I'm using:

                                    https://github.com/asymworks/benthos/blob/master/src/controls/maplocationeditor.hpp
                                    https://github.com/asymworks/benthos/blob/master/src/controls/maplocationeditor.cpp
                                    https://github.com/asymworks/benthos/blob/master/res/mapview/locpick.html

                                    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