javascript - Google map - 加载时可以出现弹出窗口吗?

标签 javascript google-maps

我只是想知道如何让我的自定义 Google map 的信息弹出窗口显示在加载时,而不是单击时?这样当页面加载时它就起来了?

我有生成 map 和自定义指针的代码,以及带有地址信息的弹出窗口(现在是虚拟文本)。但我希望这个窗口出现在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>

最佳答案

您可以使用'idle'事件:

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

本地图的所有 block 都被完全加载时,该事件将被触发。

关于javascript - Google map - 加载时可以出现弹出窗口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13587064/

相关文章:

javascript - Angularjs模块工厂服务问题

javascript - 为什么我在数组中推送的值未定义?

java - 显示位置并将相机置于其中心位置时出现问题

ios - 如何找到坐标所在的海洋

javascript - 标记未显示在我的 map 上

javascript - 打开带有片段标识符的 URL 时防止默认跳转?

javascript - 在 JavaScript 中启用/禁用导航项的最佳方式?

c# - 母版页中我的网络内容表单中的谷歌地图

javascript - 未捕获的语法错误 : Unexpected token &

google-maps - 街景全景完全灰色