我试图仅打印用户单击“打印”按钮时在地图上看到的内容,但是我不知道为什么,地图会完全更改.
我只希望地图调整图像大小以完全适合打印.地图的大小是无关紧要的.
但是我得到这个:
谢谢!
解决方法:
Google 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.
如前所述,一种解决方案是使用静态地图API.您只需要获取地图的视点(边界)并将其发送到静态地图API,然后检索可以轻松打印的图像即可. Static Map API甚至支持标记.
一个例子
https://maps.googleapis.com/maps/api/staticmap?center=*lyn+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