QWebView and Google Maps JS API v3
-
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.htmlQt 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!
-KlingDoes anyone know how to intercept the touch UI from GMaps API?
-
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 -
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..
-
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?
-
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.
-
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.
-
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"));
...
@ -
[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).
-
I would like to say thank you, too
Nice work! -
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")); -
[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 :-)
-
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 ?
-
[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. -
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