[英]how to open infowindow in page load in google map
i have one marker in google map . 我在Google地图上有一个标记。 and it has one info window with some content .
它有一个包含一些内容的信息窗口。 i want it should open automatically when page renders not in click event .
我希望它应该在页面渲染不在click事件时自动打开。
function initMap() {
var myLatLng = new google.maps.LatLng(22.804270950051844, 86.18359432304942),
myOptions = {
zoom: 14,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
map = new google.maps.Map(document.getElementById('map-canvas'), myOptions),
marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: 'http://maps.google.com/mapfiles/ms/micons/green.png',
label: "1",
});
var contentString = 'no 1';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('click', function () {
infowindow.open(map, marker);
});
infowindow.open(map, marker);
marker.setMap(map);
}
don't put in listener but in body initMap code 不要放在侦听器中,而是放在主体initMap代码中
function initMap() {
var myLatLng = new google.maps.LatLng(22.804270950051844, 86.18359432304942),
myOptions = {
zoom: 14,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
map = new google.maps.Map(document.getElementById('map-canvas'), myOptions),
marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: 'http://maps.google.com/mapfiles/ms/micons/green.png',
label: "1",
});
var contentString = 'no 1';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(map, marker);
}
and if you have problem with overlapping try assigne a proper new position eg: ( position
by default contains the LatLng of the object at which this info window is anchored) 并且如果您在重叠方面遇到问题,请尝试分配一个合适的新位置,例如:(默认情况下,
position
包含此信息窗口所锚定对象的LatLng)
var infowindow = new google.maps.InfoWindow({
content: contentString,
position: new google.maps.LatLng(22.80427+ 0.000005 , 86.18359+ 0.000005)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.