1

我只是想知道如何让我的自定义谷歌地图的信息弹出窗口出现在加载时,而不是点击时?这样页面加载时它就起来了吗?

我有生成地图和自定义指针的代码,以及带有地址信息的弹出窗口(现在是虚拟文本)。但我希望这个窗口出现 onload,而不是 onclick?

感谢您的帮助-我的代码如下!

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">
    function initialize() {
        var latlng = new google.maps.LatLng(55.9724676,-3.1876244);
        var settings = {
            zoom: 15,
            center: latlng,
            mapTypeControl: true,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP};
        var map = new google.maps.Map(document.getElementById("map_canvas"), settings);

var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h1 id="firstHeading" class="firstHeading">Høgenhaug</h1>'+
    '<div id="bodyContent">'+
    '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>'+
    '</div>'+
    '</div>';

var infowindow = new google.maps.InfoWindow({
    content: contentString
});


var companyLogo = new google.maps.MarkerImage('mapmarker-sm.png',
    new google.maps.Size(128,128),
    new google.maps.Point(0,0),
    new google.maps.Point(50,50)
);
var companyShadow = new google.maps.MarkerImage('images/logo_shadow.png',
    new google.maps.Size(128,128),
    new google.maps.Point(0,0),
    new google.maps.Point(65, 50)
);
var companyPos = new google.maps.LatLng(55.9724676,-3.1876244);
var companyMarker = new google.maps.Marker({
    position: companyPos,
    map: map,
    icon: companyLogo,
    shadow: companyShadow,
    title:"Company Title"
});

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

};

</script>

</head>

<body onload="initialize()">
  <div id="map_canvas" style="width: 100%; height:500px"></div>
</body>


</html>
4

1 回答 1

1

您可以使用'idle'事件:

google.maps.event.addListenerOnce(map, 'idle', function() {
   infowindow.open(map,companyMarker);
});

当地图的所有块将完全加载时,将触发该事件。

于 2012-11-27T15:10:29.697 回答