使用html2canvas捕获图像后无法加载谷歌地图

问题描述 投票:0回答:1

我想使用html2canvas捕获谷歌地图图像,但问题是当我捕获图像时除了方向我看不到谷歌地图。有人可以帮我这个。下面是参考图片我也附上了代码。

function getScreenShot() {

      html2canvas(document.querySelector("#map")).then(canvas => {

      var img = canvas.toDataURL();
      window.open(img);
      height=height,
      width=width

  });
 }

Before capturing image.

After capturing image.

javascript html css web html2canvas
1个回答
0
投票

你为什么不使用谷歌地图的静态地图概念?使用静态地图,您可以轻松创建图像。您可以看到以下功能相同。

  function getScreenShot() {
    //google static map url
    var staticM_URL = "https://maps.googleapis.com/maps/api/staticmap";

    //Set the Google Map Center.
    staticM_URL += "?center=" + mapOptions.center.lat() + "," + mapOptions.center.lng();

    staticM_URL  += "&size=520x650";  //Set the Google Map Size. 

    staticM_URL  += "&zoom=" + mapOptions.zoom;  //Set the Google Map Zoom. 

    staticM_URL  += "&maptype=" + mapOptions.mapTypeId;//Set the Google Map Type.

    //Loop and add Markers.
    for (var i = 0; i < markers.length; i++) {
        staticM_URL  += "&markers=color:red|" + markers[i].lat + "," + markers[i].lng;
    }

   window.open(staticM_URL);
}

一些参考网址将帮助您。 https://staticmapmaker.com/google/ https://www.aspsnippets.com/Articles/Take-Screenshot-Snapshot-of-Google-Maps-using-JavaScript.aspx

© www.soinside.com 2019 - 2024. All rights reserved.