我试图只打印用户在点击“打印”按钮时在 map 中看到的内容,但我不知道为什么, map 完全改变了。
我只希望 map 调整图像大小以完全适合打印。 map 是小还是大都没有关系。
但是我得到了这个:
谢谢!
最佳答案
谷歌地图 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/