采用QWebEngine,需Qt5.5以上
-
Qt调用显示百度地图
-
Qt传送json数据,地图端生成根据数据生成marker。
-
Qt端通过按钮新增marker和改变地图端marker状态
-
地图端实现右键菜单,通过菜单改变数据(调用Qt端的接口改变,然后传递到地图端)
Qt和百度地图交互示例
你好:
目前想做一個關於GPS結合Qt的小專案,目前選擇Google Map作為我的地圖,在使用QWebengineView時事可以順利載入地圖的,但我無法使用 webview->page()->runjavascript()
去操作Javascript內的function 程式碼 。
QUrl url("qrc:/map.html");
QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::PluginsEnabled,true);
QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled,true);
QWebEnginePage *page = new QWebEnginePage(this);
QWebChannel *channel = new QWebChannel(this);
page->load(url);
page->setWebChannel(channel);
ui->widget->setPage(page);
QString js=QString("var marker = new google.maps.Marker({ ")+
QString("position: new google.maps.LatLng(24.705311, -74.2581939),")+
QString(" map: map,")+
QString("title: \"Marker A\",")+
QString(" }); ");
ui->widget->page()->runJavaScript(js,[](const QVariant &result){ qDebug() << result.toBool(); });
錯誤回報:
js: Uncaught ReferenceError: google is not defined
目前才剛接觸Qt 的Web功能和javascript,所以也不知道問題出在哪裡?
另外一定要使用Qt webchannel才能對javascript操作嗎?
謝謝!!
開發環境:
Ubuntu 16.04
Qt 5.7
你好,在地图上输入成都原点坐标(104.07°,30.67°),map上标记的位置与城市实际地标有上千米的偏移。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.