通过旋转和倾斜向 Google 地图添加图像叠加层
我正在尝试将图像叠加到 Google 地图上,并且使用此处找到的说明:
https://developers.google.com/maps/documentation/javascript/examples/groundoverlay-simple
当我尝试使用“标题”属性时,地图会正确旋转,但是图像也会正确旋转。我尝试使用图像变换来旋转图片,但最终在地图上出现一个白色框。
下面是我的 javascript
let historicalOverlay;
function initMap() {
const map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 24.960864, lng: 55.150841 },
zoom: 16,
tilt: 47.5,
heading: 120,
mapId: "90f87356969d889c",
});
const imageBounds = {
north: 24.9717265,
south: 24.9500015,
east: 55.161841,
west: 55.139841,
};
historicalOverlay = new google.maps.GroundOverlay("https://res.cloudinary.com/defmmlrqg/image/upload/a_120/v1646695548/test/img32_iidhie.jpg", imageBounds);
historicalOverlay.setMap(map);
}
这是我的 HTML
<!DOCTYPE html>
<html>
<head>
<title>Tilt and Rotation</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<!-- jsFiddle will insert css and js -->
</head>
<body>
<div id="map"></div>
<!-- Async script executes immediately and must be after any DOM elements used in callback. -->
<script
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&v=beta&channel=2" async></script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将按 url 的旋转与 URL 上的“a_120”部分一起使用。用这种方法你的图像并没有真正旋转。您需要使用自定义叠加层。在上一个链接的示例中,要旋转图像,请修改自定义叠加类的
draw
方法,添加类似“查看 这篇文章了解更多信息。
Don't use the rotation by url with the "a_120" part on the URL. You're image don't really rotate with this method. You need to use custom overlay. In the exemple in the previous link, to rotate you're image, modify the
draw
method of the custom overlay class by adding something likeTake a look at this post for more infos.