这是演示我注意到的问题的代码。
> JSFiddle <
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type='text/css'>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
p,h4 {
margin:0;
}
#map-canvas{
width:425px;
height:300px;
margin:1em;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type='text/javascript'>//<![CDATA[
function initialize() {
var myLatlng = new google.maps.LatLng(-38.06794990,145.30192430);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var contentString = '<div style="width:300px;"><H4>Heading</H4><P><B>Address:</B> Community Centre 51L The Strand, Narre Warren South 3805</P></div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Food Waste and Organics workshop'
});
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function(event) {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
//]]>
</script>
</body>
</html>
当信息窗口通过点击事件打开时,它可以正常打开。但是,如果它在窗口加载事件中完成,它不会正确对齐地图区域中的信息窗口,并且信息窗口的顶部被切断。即使增加地图 div 的高度似乎也无济于事。
谢谢,库马尔。