我有一张带有InfoWindow 的地图。 我需要在页面加载时打开这个InfoWindow。 在 API 中有一个 < code> InfoWindow. Open 方法, 但效果不好 。
这是我目前的代码
<html>
<head>
<link rel="stylesheet" href="/static/css/map.css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var infoWindow = null;
var map = null;
var marker;
function getInfoWindowEvent(marker, content) {
infoWindow.close()
infoWindow.setContent(content);
infoWindow.open(map, marker);
}
function initialiseMap() {
infoWindow = new google.maps.InfoWindow();
var myLatlng = new google.maps.LatLng({MAP_6_LATITUDE}, {MAP_6_LONGTITUDE});
var myOptions = {
zoom: 12,
streetViewControl: false,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_side_canvas"), myOptions);
var bounds = new google.maps.LatLngBounds();
var image = new google.maps.MarkerImage(
/static/img/markers/image.png ,
new google.maps.Size(32,37),
new google.maps.Point(0,0),
new google.maps.Point(16,37)
);
var shadow = new google.maps.MarkerImage(
/static/img/markers/shadow.png ,
new google.maps.Size(54,37),
new google.maps.Point(0,0),
new google.maps.Point(16,37)
);
var shape = {
coord: [29,0,30,1,31,2,31,3,31,4,31,5,31,6,31,7,31,8,31,9,31,10,31,11,31,12,31,13,31,14,31,15,31,16,31,17,31,18,31,19,31,20,31,21,31,22,31,23,31,24,31,25,31,26,31,27,31,28,31,29,30,30,29,31,23,32,22,33,21,34,20,35,19,36,12,36,11,35,10,34,9,33,8,32,2,31,1,30,0,29,0,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,1,1,2,0,29,0],
type: poly
};
var myLatlng = new google.maps.LatLng({MAP_6_LATITUDE}, {MAP_6_LONGTITUDE});
marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: image,
shadow: shadow,
shape: shape,
title:"{TITLE}"
});
google.maps.event.addListener(marker, click , function() {
getInfoWindowEvent(marker, "<a href= {LINK} ><img src= /system/scripts/i.php?f={MAIN_PHOTO_21}&w=90&h=70&crop=1 class= hotel-img ></a><div class= rating data-rate_level= {STARS_52} ></div><br /><a href= {LINK} ><h3>{TITLE}</h3></a><div class= price >From <div class= text ><?=number_format($minprice[0][0],0, , , ); ?> USD</div></div>");
});
infoWindow.open(map);
return map;
}
</script>
</head>
<body onLoad="initialiseMap(); " id="map_side_canvas" style="margin:0;padding:0;width:100%;height:100%;">
</body>