【发布时间】:2018-05-24 15:58:30
【问题描述】:
我正在尝试拍摄由谷歌地图上绘制的矩形包围的区域的快照。是否可以拍摄矩形下方区域的快照?我已经搜索了答案,但找不到任何有用的信息。
我尝试使用静态地图 API 通过指定地图中心、缩放级别、图像宽度和图像高度来拍摄矩形下方区域的快照。喜欢 https://maps.googleapis.com/maps/api/staticmap?center=CENTER 矩形&zoom=地图缩放级别&size=矩形宽度和高度&maptype=satellite&key=API 密钥
这是我试过的代码,
var zoom = map.zoom;
var centre = rectangle.getBounds().getCenter(); //rectangle is the shape drawn on the map
var spherical = google.maps.geometry.spherical;
bounds = rectangle.getBounds(); //rectangle is the shape drawn on the map
cor1 = bounds.getNorthEast();
cor2 = bounds.getSouthWest();
cor3 = new google.maps.LatLng(cor2.lat(), cor1.lng());
cor4 = new google.maps.LatLng(cor1.lat(), cor2.lng());
width = spherical.computeDistanceBetween(cor1,cor3);
height = spherical.computeDistanceBetween( cor1, cor4);
现在我使用这个 URL 下载了图片,
"https://maps.googleapis.com/maps/api/staticmap?center=" + center.lat() + "," + center.lng() + "&zoom=" + zoom + "&size=" + width + "x" + height + "&maptype=satellite&key= API_KEY"
我得到了图像,但图像不包括矩形包围的整个区域(它太小)。我做错了什么?有没有其他方法可以做到?
【问题讨论】:
标签: javascript google-maps google-maps-api-3 google-static-maps