Javascript 谷歌地图:如何防止InfoWindow移动地图
使用谷歌地图API v3 我注意到如果我在地图边界附近有一个地图标记。。。如果我点击 标记图标,以便信息窗口显示,我的整个地图移动,以便 标记信息窗口居中 我不想让我的地图移动Javascript 谷歌地图:如何防止InfoWindow移动地图,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,使用谷歌地图API v3 我注意到如果我在地图边界附近有一个地图标记。。。如果我点击 标记图标,以便信息窗口显示,我的整个地图移动,以便 标记信息窗口居中 我不想让我的地图移动 问题:当信息窗口接近地图边界的末端时(默认情况下会导致信息窗口居中并移动地图),如何防止地图移动?由于您使用的是v3,您可以使用disableAutoPan选项简单地防止信息窗口移动地图,如以下示例()所示: 谷歌地图disableAutoPan演示 var mylatng=newgoogle.maps.LatLng(
问题:当信息窗口接近地图边界的末端时(默认情况下会导致信息窗口居中并移动地图),如何防止地图移动?由于您使用的是v3,您可以使用
disableAutoPan
选项简单地防止信息窗口移动地图,如以下示例()所示:
谷歌地图disableAutoPan演示
var mylatng=newgoogle.maps.LatLng(37.44,-122.14);
变量myOptions={
缩放:4,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
var map=new google.maps.map(document.getElementById(“map”),myOptions);
var infowindow=new google.maps.infowindow({
内容:"测试",,
真的吗
});
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“测试标记”
});
google.maps.event.addListener(标记'click',函数(){
信息窗口。打开(地图、标记);
});
截图:
agm marker info有一个名为[disableAutoPan]的属性,如果将其设为false,则不会移动位于地图边框边缘附近的地图信息窗口
标记信息:“A”
<!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>