You can use Geolocation API with Desktop applications using QWebView
?
- I've tried Qt WebKit and HTML5 geolocation , but it does not work.
- I tried it's the qt5 position api support for desktop app (like mac or windows) , but this answer is about the Qt APIs, I want to know if it is not possible on the Desktops so it may be possible to customize the "event" as it does with
qwebkitplatformplugin
which is used to customize some features inqtwebkit
(MultipleSelections, Notifications, Haptics, TouchInteraction, FullScreenVideoPlayer and SpellChecker).
I tried to use PermissionGrantedByUser
, but it does not work:
void WebPage::permissionRequested(QWebFrame* frame, Feature feature)
{
switch (feature) {
case Geolocation:
qDebug() << "GEO-Location: PermissionGrantedByUser";
setFeaturePermission(frame, feature, PermissionGrantedByUser);
break;
default:
qDebug() << "";
}
}
- I've tried
QT += positioning
, but it does not work - I've tried
TARGET.CAPABILITY += NetworkServices Location
, but it does not work. I believe this flag is for smartphones, like Symbian.
The events displayLocation
and watchPosition
are never triggered and using { timeout: ... }
will show Timeout expired
after the given time:
<script>
function displayError(err) {
document.getElementById("geo").innerHTML = ("Código de erro: " + err.code +
" / mensagem: " + err.message);
}
function displayLocation(position) {
document.getElementById("geo").innerHTML = [
"latitude:" + position.coords.latitude,
"longitude:" + position.coords.longitude
].join(", ");
}
function getMyLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(function(a, b, c) {
console.log(a, b, c);
document.getElementById("geo").innerHTML = "Testando...";
});
navigator.geolocation.getCurrentPosition(displayLocation, displayError, {
enableHighAccuracy: false,
timeout: 1000,
maximumAge: 0
});
} else {
document.getElementById("geo").innerHTML = "Geo-Localização não suportado";
}
}
window.onload = function() {
getMyLocation();
};
</script>
<div id="geo"></div>
I think I have to create a plugin with Qt and put it in the qtDir/compiler/plugins/position
folder, but I do not know where to start creating this plugin.
How can I do this?
Is it possible to customize events and send simulated coordinates or a third-party library (I'm not asking for a library or JavaScript alternatives) for navigator.geolocation.getCurrentPosition
?
Extra information
If you use QT_DEBUG_PLUGINS=1
in debug mode ( debug mode
) the Application Output returns this (note that the first line of log is generated by WebPage::permissionRequested
):
GEO-Location: PermissionGrantedByUser
QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt5.4.0/5.4/mingw491_32/plugins/position" ...
QFactoryLoader::QFactoryLoader() looking at "C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll"
Found metadata in lib C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll, metadata=
{
"IID": "org.qt-project.qt.position.sourcefactory/5.0",
"MetaData": {
"Keys": [
"positionpoll"
],
"Monitor": true,
"Position": false,
"Priority": 1000,
"Provider": "positionpoll",
"Satellite": false
},
"className": "QGeoPositionInfoSourceFactoryPoll",
"debug": false,
"version": 328704
}
"The plugin 'C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)"
not a plugin
QFactoryLoader::QFactoryLoader() looking at "C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpolld.dll"
Found metadata in lib C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpolld.dll, metadata=
{
"IID": "org.qt-project.qt.position.sourcefactory/5.0",
"MetaData": {
"Keys": [
"positionpoll"
],
"Monitor": true,
"Position": false,
"Priority": 1000,
"Provider": "positionpoll",
"Satellite": false
},
"className": "QGeoPositionInfoSourceFactoryPoll",
"debug": true,
"version": 328704
}
Got keys from plugin meta data ("positionpoll")
QFactoryLoader::QFactoryLoader() checking directory path "C:/projects/webview-example/debug/position" ...
In other words, when I run JavaScript navigator.geolocation
the Qt calls the C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll
, but does not return any information back to QWebView
.