我只是想知道如何让我的自定义Google地图的信息弹出窗口出现加载,而不是点击?这样一来,当页面加载时它就会出现?
我有代码生成地图和自定义指针,以及带有地址信息的弹出窗口(现在是虚拟文本)。但我希望这个窗口显示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>
答案 0 :(得分:1)
您可以使用'idle'
事件:
google.maps.event.addListenerOnce(map, 'idle', function() {
infowindow.open(map,companyMarker);
});
当完全加载地图的所有块时,将触发该事件。