Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEngineView load baidu map failed

QWebEngineView load baidu map failed

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 504 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.
  • K Offline
    K Offline
    k423
    wrote on last edited by
    #1

    I use the demo of baiduMap's JS API(V2),and the html work in Edge;
    But it do not work in QWebEngineView,and log these

    "file:///D:/LocalProject/Qt/baiduMap/map/baiduMap_demo.html"
    [22876:24104:0525/184414.800:WARNING:render_frame_host_impl.cc(901)] InterfaceRequest was dropped, the document is no longer active: blink.mojom.PermissionService
    [22876:24104:0525/184414.800:WARNING:render_frame_host_impl.cc(901)] InterfaceRequest was dropped, the document is no longer active: blink.mojom.PermissionService
    js: Uncaught ReferenceError: BMap is not defined
    

    I don' know why BMap is not defined
    see the body of html

    <body>
    
        <div id='allmap'></div>
        <div id='result'>
            经度: <input id="lng" type="text" />
            纬度: <input id="lat" type="text" />
            <button onclick="theLocation()">查询</button>
        </div>
    
        <script>
            // 百度地图API功能-BMap-V2.0
            var map = new BMap.Map("allmap");
            map.centerAndZoom(new BMap.Point(116.331398, 39.897445), 11);
            map.enableScrollWheelZoom(true);
    
            // 用经纬度设置地图中心点
            function theLocation() {
                if (document.getElementById("lng").value != "" && document.getElementById("lat").value != "") {
                    map.clearOverlays();
                    var new_point = new BMap.Point(document.getElementById("lng").value, document.getElementById("lat").value);
                    var marker = new BMap.Marker(new_point);  // 创建标注
                    map.addOverlay(marker);              // 将标注添加到地图中
                    map.panTo(new_point);
                }
            }      
        </script>
    </body>
    

    and my QT codes

    void MainWindow::on_pushButton_2_clicked()
    {
        QString mappath;
    
        mappath = exepath + "map/baiduMap_demo.html";
        qDebug()<<mappath;
        m_view->load(QUrl(mappath));
        m_view->show();
    }
    

    otherwise, 'm_view'can load and show ‘https://www.bilibili.com/’.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @k423 said in QWebEngineView load baidu map failed:

      js: Uncaught ReferenceError: BMap is not defined

      BMap is from Baidu map SDK, you should import Baidu SDK first.
      from here: https://github.com/huiyan-fe/react-bmap/issues/4

      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