Create an html file 'GMap.html' for Google map like this
In Qt5.5 =<
<!DOCTYPE html>You must save 'GMap.html' file in your application directory. Then load this file in your Qt application.
<html>
<body>
<h1>How to load Google map in Qt application?</h1>
<div id="GMap" style="width:600px;height:600px;"></div>
<script>
function LoadGMap()
{
var mapOptions = {
center: new google.maps.LatLng(36.778259, -119.417931),
zoom: 5
}
var map = new google.maps.Map(document.getElementById("GMap"), mapOptions);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=LoadGMap"></script>
</body>
</html>
In Qt5.5 =<
Header: #include <QWebView>In Qt5.6 >=
QString HTMLFilepath = "YOUR_APPLICATION_PATH+/GMap.html";
QWebView *HTMLPage = new QWebView(parent);
HTMLPage->load(QUrl(QUrl::fromLocalFile(HTMLFilepath));
HTMLPage->show();
Header: #include <QWebEngineView>'load(url)' loads the specified url and displays it.
QString HTMLFilepath = "YOUR_APPLICATION_PATH+/GMap.html";
QWebEngineView *HTMLPage = new QWebEngineView(parent);
HTMLPage->load(QUrl(QUrl::fromLocalFile(HTMLFilepath));
HTMLPage->show();
No comments:
Post a Comment