javascript - 打印整个页面时如何修复 Google Map API?

标签 javascript html css google-maps printing

我试图只打印用户在点击“打印”按钮时在 map 中看到的内容,但我不知道为什么, map 完全改变了。

我只希望 map 调整图像大小以完全适合打印。 map 是小还是大都没有关系。

这是用户看到的: enter image description here

但是我得到了这个:

纵向 enter image description here

风景 enter image description here

谢谢!

最佳答案

谷歌地图 API does not support打印:

Printing from the JavaScript API is not supported. This is because printing support is inconsistent across commonly used browsers. We recommend using the Static Maps API for printing purposes.

如前所述,一种解决方案是使用静态 map API。您只需要获取 map 的视点(边界)并将其发送到静态 map API 并检索可以轻松打印的图像。 Static Map API甚至支持标记之类的东西。

一个例子

https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap
&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318
&markers=color:red%7Clabel:C%7C40.718217,-73.998284
&key=YOUR_API_KEY

关于javascript - 打印整个页面时如何修复 Google Map API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41354384/

相关文章:

javascript - 当 AngularJS 中的模型更新时, View 不会更新

javascript - CSS3 动画后的 iOS 右侧空白

html - 创建一个仅在小屏幕尺寸下显示的子列

javascript - 两个功能相互干扰

javascript - 如何在 vanilla javascript 中用更好的替代方法替换 onclick?

javascript - Bootstrap 5 Offcanvas - 检测 offcanvas 项目是否在加载时显示

javascript - React - 在对象之间定义更大的字符串

javascript - 将 jquery 模态弹出脚本附加到按钮事件

javascript - 下拉菜单隐藏在图像后面

css - 我的 <h1> 标签没有解决 Firefox 中的样式,但它在 IE 中