打印整个页面时如何修复Google Map API? [英] How to fix the Google Map API when print the whole page?

查看:117
本文介绍了打印整个页面时如何修复Google Map API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图只打印用户在地图上看到的内容,当他点击打印按钮时,但我不知道为什么地图完全改变。



我只是希望地图调整图像的大小,使其完全适合打印。如果地图大小不一定很重要。



这是用户看到的内容:



但我收到了:

纵向



风景



感谢!

解决方案

Google Map API 不支持打印:


打印从JavaScript API不支持。这是因为
打印支持在常用浏览器中不一致。我们b $ b推荐使用静态地图API进行打印。


如前所述,解决方案是使用Static Map API。您只需获取地图的视角(边界)并将其发送到静态地图API并检索可轻松打印的图像。 静态地图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


I'm trying to just print exactly what the user sees in maps when he clicks in the Print Button, but I don't know why, the map changes completely.

I just want that the map resizes the image to fit exactly in the Print. It doesn't matter if the maps will be small or large.

This is what the user sees:

But I'm getting this:

Portrait

Landscape

Thanks!

解决方案

Google Map API does not support printing:

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.

As it is mentioned, a solution is to use Static Map API. You simply need to get the viewpoint of the map (boundaries) and send it to static map API and retrieve an image that you can easily print. The Static Map API even supports things like markers.

An example

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

这篇关于打印整个页面时如何修复Google Map API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆