如何将谷歌地图格式更改为jpeg?

时间:2018-03-12 16:31:53

标签: javascript google-maps google-maps-api-3

如何在screenshot更改Google地图图片格式? 我看到我们在https://developers.google.com/maps/documentation/static-maps/intro上有地图参数。其中一个是

  

格式(可选)定义结果图像的格式。默认情况下,Google Static Maps API会创建PNG图像。有几种可能的格式,包括GIF,JPEG和PNG类型。您使用哪种格式取决于您打算如何呈现图像。 JPEG通常提供更大的压缩,而GIF和PNG提供更多细节。

但如果我使用它,一切都没有改变。这是我的代码示例

<html>
    <head>
        <title>Simple Map</title>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <style>
          /* Always set the map height explicitly to define the size of the div
           * element that contains the map. */
          #map {
            display: block;
            width: 100%;
            height: 500px;
          }
          /* Optional: Makes the sample page fill the window. */
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
        </style>
      </head>
      <body>
        <div id="map"></div>
        <script>
          var map;
          function initMap() {
            map = new google.maps.Map(document.getElementById('map'), {
              center: {lat: -34.397, lng: 150.644},
              zoom: 8,
              format: 'jpg'
            });
          }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
        async defer></script>
      </body>
</html> 

https://jsfiddle.net/7w3f9b55/33/ (来自谷歌示例的基本代码)。

1 个答案:

答案 0 :(得分:1)

您链接到的文档适用于静态地图,您希望将单个静态图像嵌入到网页中。

谷歌地图javascript api不允许你控制图像类型,你为什么要这样做?

相关问题