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.
  • C Offline
    C Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on 7 Nov 2010, 23:56 last edited by
    #1

    I'm trying to use google maps in my app using js api v3. When using Qt WebKit the map displays only some degraded controls and all the mouse dragging/zooming is gone. On the other hand "http://maps.google.com":http://maps.google.com works just fine. I've tried to set different useragents in subclassed QWebPage, but this doesn't change anything. Also I tried to modify my map code to force using mouse and enable scroll zoom, but again this seems to be ignored.

    This behaviour can be observed for example using FancyBrowser from examples/demos and navigating to this tutorial page
    "http://code.google.com/intl/pl/apis/maps/documentation/javascript/examples/map-simple.html":http://code.google.com/intl/pl/apis/maps/documentation/javascript/examples/map-simple.html

    I'd like to know if this is a Qt Webkit limitation (can I workaround it in any way?) or google apis are somehow blocking full funcionality in this case. The v2 apis are working ok, but they've been deprecated, and I'd hate to have to fall back to them.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcrochik
      wrote on 9 Nov 2010, 02:27 last edited by
      #2

      I would assume the right combination of user agent and MapOptions should do the trick. I have created a "google maps front-end" application for the n900 but can't remember if panning worked using the "mouse". On my case I didn't want to use the "standard" pan (or zoom) so I filtered the mouse events to implement a kinetic scrolling and used the "volume buttons" for zoom.

      It is just a guess but I would assume that if you use the "iphone" or "android" user agents google maps will try to listen to "gestures" events instead of mouse events and it will not work. Probably using a desktop browser useragent (like "firefox") will help the testing.

      Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 9 Nov 2010, 10:50 last edited by
        #3

        Thanks fcrochik but unfortunetly i tried only desktop useragents (chrome, firefox and IE). It seems to be ignored entirely.
        This is true that maps pick up the android "theme" by default (it's strange that it ignores useragent. I wonder how maps choose the layout then..), but with the right set of map options I managed to make it look more desktopish.

        The only thing is that it for some reason ignores the "draggable" option which is suppose to be responsible for what I want. I don't want to re-invent the wheel and custom code the movement. I know this is just a few lines of code but I'm simply curious why the default mechanism doesn't work.
        Also it's not possible to easily create the 'smooth scrollwheel zoom' by hand, and it also is default on desktop browsers, but the setting is ignored on qt webkit.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fcrochik
          wrote on 9 Nov 2010, 12:58 last edited by
          #4

          crossblades:
          I just tested with another application I created and, at least, the dragging (pan) works just fine for http://code.google.com/intl/pl/apis/maps/documentation/javascript/examples/map-simple.html. I tried using the "iphone" user agent.

          Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fcrochik
            wrote on 9 Nov 2010, 13:04 last edited by
            #5

            crossblades:
            Quick update: Even using the "default" user agent it worked on my n900 (the pan).
            Just to make sure: Do you have the mouseTracking enabled for the webview? (Most of the time the answer to complex question is the most simple)

            Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on 9 Nov 2010, 13:42 last edited by
              #6

              fcrochik:
              Yes, mouse tracking is enabled, but this doesn't matter because when dragging the mouse button is pressed anyway (mouse tracking enables mouse events without buttons pressed right?).
              "iphone" user agent doesn't change anything also.
              I don't have n900, but on desktop(win XP/7x64) this is what the example looks like:
              "shot1":http://img258.imageshack.us/img258/9302/shot1.jpg
              And this is what happens if I try to drag:
              "shot2":http://img600.imageshack.us/img600/9490/shot2.jpg
              I then tried to change map options like so:
              @naviOptions = {
              position: google.maps.ControlPosition.TOP_LEFT,
              style: google.maps.NavigationControlStyle.ZOOM_PAN
              }
              myOptions = {
              zoom: 8,
              center: myLatlng,
              draggable: true,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              keyboardShortcuts: true,
              mapTypeControl: true,
              navigationControl: true,
              scrollwheel: true,
              disableDoubleClickZoom: false,
              streetViewControl: false,
              navigationControlOptions: naviOptions
              }@
              This is what it looks like with changed map options:
              "shot3":http://img585.imageshack.us/img585/1567/shot3w.jpg
              All controls work except for mouse drag and wheel zoom.

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fcrochik
                wrote on 9 Nov 2010, 14:49 last edited by
                #7

                Good point about the mousetracking :)

                Very odd... I couldn't resist and compiled my application for the desktop to find out that you are right. The tracking does not work on the desktop (but it does on the n900) for http://code.google.com/intl/pl/apis/maps/documentation/javascript/examples/map-simple.html. Tracking and mousewheel work for google.com/maps.

                I tried a few things but couldn't figure out why it does not work. I would have to guess the google javascript API is checking something different than the user agent.

                Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  zmilton
                  wrote on 10 Nov 2010, 14:22 last edited by
                  #8

                  Hello,

                  Has anyone found out any more information about this? My application seemed to work fine before the V3 upgrade and now I cannot get the scrolling/mousewheel zooming functionality to work at all. I've tried explicitly giving the map scrollwheel and draggable settings like the above poster, but that doesn't seem to work.

                  When I try to drag I get the thumbnail'd version of the map under my cursor like I am trying to drag an image.

                  Also, is there something special about maps.google.com, because that does seem to work just fine using QWebView.

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nelas
                    wrote on 3 Dec 2010, 13:57 last edited by
                    #9

                    I'm also experiencing this issue (which made my application useless). So, I found this "message":https://lists.webkit.org/pipermail/webkit-qt/2010-November/000974.html that might indicate the path to a solution. Pasting it here for practical reasons:

                    bq. On 11/20/2010 08:42 AM, ext Gary.Wzl wrote:

                    Browser based on Qt port of webkit (qt demo browser or arora )can't be dragged google map when webpage is loaded properly.
                    http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/examples/index.html

                    Qt version is 4.7.0

                    bq. Looks like it's giving you a multi-touch version of the page. Some quick testing shows that QtWebKit has document.documentElement.ontouchstart and friends, whereas Chromium, Firefox, Opera etc do not (at least not on my desktop machine.) The right solution is to get Google Maps to stop sending you the touch UI, but you could of course compile QtWebKit with DEFINES+=ENABLE_TOUCH_EVENTS=0 (this is currently set to 1 in WebCore/features.pri)
                    Hope that helps!
                    -Kling

                    Does anyone know how to intercept the touch UI from GMaps API?

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nemoxu
                      wrote on 8 Dec 2010, 03:18 last edited by
                      #10

                      I had the some issue . And I used the google v3.1 API , map can drap/zoom. Include the google map api :
                      http://maps.google.com/maps/api/js?v=3.1&sensor=true

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        nelas
                        wrote on 8 Dec 2010, 10:40 last edited by
                        #11

                        Thanks nemoxu! Adding the version (v=3.1) to the script solved the problem for me.

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on 8 Dec 2010, 11:23 last edited by
                          #12

                          Yeah, it works, thanks!

                          It doesn't work in later versions though (3.2, 3.3) so I hope it's not like designing for IE6 - relying on a "known bug" to make it work..

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            fcrochik
                            wrote on 8 Dec 2010, 17:13 last edited by
                            #13

                            I haven't had a chance to try but using qt webkit 2.1 (I think that is how the new branch is called) should give us all the "gestures" and the "location" api. I remember seeing a message about the beta source code being available for download.... Anybody has tried it?

                            Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

                            1 Reply Last reply
                            0
                            • 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

                                          • Login

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