加载地图和标记时自动打开 Google 地图 V2 InfoWindow
如何在地图加载时调用标记的信息窗口来打开。由于某种原因,Google 文档仅显示如何响应点击操作。我不太擅长 JavaScript,所以任何帮助将不胜感激。谢谢!
这是我当前的代码,但由于某种原因,没有出现地图。但没有错误可以帮助我找出问题所在......
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var map = new GMap2(document.getElementById("map"));
var point = new GLatLng(53.3407791, -6.2596385);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(point, 16);
// Set up three markers with info windows
var html = 'South Anne Street,<br />Dublin 2, Ireland';
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(html); // This opens the info window automatically
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
How do you call a markers' infowindow to open when the map loads. For some reason the Google documentation only shows how to respond to a click action. I'm not very good with JavaScript so any help would be appreciated. Thanks!
this is my current code, but for some reason, no map appears. But there is no error to help me pinpoint the problem...
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var map = new GMap2(document.getElementById("map"));
var point = new GLatLng(53.3407791, -6.2596385);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(point, 16);
// Set up three markers with info windows
var html = 'South Anne Street,<br />Dublin 2, Ireland';
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(html); // This opens the info window automatically
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论