gpt4 book ai didi

javascript - Google map 信息窗口 open() panTo map 边缘

转载 作者:行者123 更新时间:2023-11-30 23:44:13 26 4
gpt4 key购买 nike

我有这两行

map.panTo(respectiveMarker.getPosition());//Center in map the respective marker
infoWindow.open(map, respectiveMarker);

当执行 infoWindow.open 时, map 平移到边缘。如果我删除这条线, map 将按预期平移到标记。

有什么想法吗?

最佳答案

由于您正在使用 v3 API您可以简单地使用 disableAutoPan 阻止 infoWindow 移动 map 。选项。

完整示例:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps disableAutoPan Demo</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>

<div id="map" style="width: 200px; height: 200px"></div>

<script type="text/javascript">

var myLatlng = new google.maps.LatLng(37.44, -122.14);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map(document.getElementById("map"), myOptions);

var infowindow = new google.maps.InfoWindow({
content: 'Test',
disableAutoPan: true
});

var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Test Marker'
});

google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});

</script>
</body>
</html>

屏幕截图:

disableAutoPan

v2 API's 中没有与 disableAutoPan 等效的功能GInfoWindowOptions ,而且我不知道有任何解决方法。

关于javascript - Google map 信息窗口 open() panTo map 边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3650933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com