Javascript 自动打开谷歌地图信息窗口

Javascript 自动打开谷歌地图信息窗口,javascript,maps,infowindow,Javascript,Maps,Infowindow,我有一张带信息窗口的地图。我需要在页面加载时打开此信息窗口。API中有一个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"&

我有一张带信息窗口的地图。我需要在页面加载时打开此信息窗口。API中有一个
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>

var infoWindow=null;
var-map=null;
var标记;
函数getInfoWindowEvent(标记、内容){
infoWindow.close()
infoWindow.setContent(content);
信息窗口。打开(地图、标记);
}
函数initialiseMap(){
infoWindow=new google.maps.infoWindow();
var mylatng=new google.maps.LatLng({MAP_6_lation},{MAP_6_longtude});
变量myOptions={
缩放:12,
街景控制:错误,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map\u side\u canvas”),myOptions);
var bounds=new google.maps.LatLngBounds();
var image=new google.maps.MarkerImage(
“/static/img/markers/image.png”,
新谷歌地图大小(32,37),
新google.maps.Point(0,0),
新谷歌地图点(16,37)
);
var shadow=new google.maps.MarkerImage(
“/static/img/markers/shadow.png”,
新谷歌地图大小(54,37),
新google.maps.Point(0,0),
新谷歌地图点(16,37)
);
变量形状={
合作伙伴:[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],
类型:“poly”
};
var mylatng=new google.maps.LatLng({MAP_6_lation},{MAP_6_longtude});
marker=新的google.maps.marker({
职位:myLatlng,
地图:地图,
图标:图像,
影子:影子,
形状:形状,
标题:“{title}”
});
google.maps.event.addListener(标记'click',函数(){
getInfoWindowEvent(标记“
来自美元”); }); 打开(地图); 返回图; }

为什么有两个叠瓦函数



我看到在第一个函数中调用了infoWindow.close()。这将从DOM中删除infoWindow。然后必须使用
new google.maps.infoWindow()重新创建它

这不应该是一个评论而不是一个答案吗?我相信一旦他修复了他的代码,他的代码会工作得更好。我已经修复了,但没有任何更改。正在讨论的代码已经更新。
function initialiseMap() {
  function getInfoWindowEvent(marker, content) {