Google maps api 3 谷歌地图api v3信息窗口在页面加载时自动打开

Google maps api 3 谷歌地图api v3信息窗口在页面加载时自动打开,google-maps-api-3,Google Maps Api 3,我正在做一个项目,我正在使用谷歌地图api-v3, 在地图上会有一些地方标记,包含我存储在信息窗口中的信息 我想知道你是否可以设置一个InfoWindow在页面加载时自动打开(即在没有用户交互的情况下自动打开) 在线搜索我能找到的似乎是它需要绑定到事件侦听器,但InfoWindow对象似乎拥有的所有事件都是鼠标事件 有人知道这样的解决方法吗 我不确定我是否完全理解你的问题,但这对我来说是一个硬编码的LatLng: var infoWindow = null; function initializ

我正在做一个项目,我正在使用谷歌地图api-v3, 在地图上会有一些地方标记,包含我存储在信息窗口中的信息

我想知道你是否可以设置一个InfoWindow在页面加载时自动打开(即在没有用户交互的情况下自动打开)

在线搜索我能找到的似乎是它需要绑定到事件侦听器,但InfoWindow对象似乎拥有的所有事件都是鼠标事件


有人知道这样的解决方法吗

我不确定我是否完全理解你的问题,但这对我来说是一个硬编码的LatLng:

var infoWindow = null;
function initialize() 
{
    infoWindow = new google.maps.InfoWindow();
    var windowLatLng = new google.maps.LatLng(43.25,-68.03);
    infoWindow.setOptions({
        content: "<div>This is the html content.</div>",
        position: windowLatLng,
    });
    infoWindow.open(map); 
} // end initialize

google.setOnLoadCallback(initialize);
var infoWindow=null;
函数初始化()
{
infoWindow=new google.maps.infoWindow();
var windowLatLng=newgoogle.maps.LatLng(43.25,-68.03);
infoWindow.setOptions({
内容:“这是html内容。”,
位置:窗板条,
});
打开(地图);
}//结束初始化
setOnLoadCallback(初始化);

我提这个问题已经很晚了,但我想和大家分享一些东西。我还搜索了它的解决方案,甚至没有从上面的解决方案中得到任何效果。然后我自己尝试了一下,找到了自己的解决方案(我不是专家,我的想法可能不好,但对我来说效果很好)。 我们一般都喜欢

var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', (function(marker) {
return function() {
    infowindow.setContent('some content here');
      infowindow.open(map, marker);
    }
})(marker));
将上述行替换为:

var infowindow = new google.maps.InfoWindow();
infowindow.setContent('some content here');
infowindow.open(map, marker);

不要等待marker的单击事件,只需设置内容并打开它(您必须定义地图、标记和信息窗口指向您的标记)。

只需打开信息窗口。打开(地图、标记);从google.maps.event.addListener中退出。应该是这样的:

      var marker = new google.maps.Marker({
      position: myLatlng1,
      map: map,
      title: 'Uluru (Ayers Rock)'

  });

  infowindow.open(map,marker);

  google.maps.event.addListener(marker, 'click', function() {
  });   

这是我的代码,它用地图和鼠标加载信息窗口

map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
    map: map,
    icon: "/images/map-marker.png",
    draggable: true,
    position: results[0].geometry.location

});
var infowindow = new google.maps.InfoWindow({
    content: "Use pin to point your exact locality"
});
google.maps.event.addListener(marker, 'mouseover', function () {
    infowindow.open(map, marker);
});
infowindow.open(map, marker);
函数initMap(){
var cairo={lat:18.519331,lng:73.849421};
var map=new google.maps.map(document.getElementById('map'){
scaleControl:对,
中心:开罗,
缩放:15,
});
var infowindow=new google.maps.infowindow;
infowindow.setContent('addAddress');
var marker=new google.maps.marker({map:map,position:cairo});
信息窗口。打开(地图、标记);
打开(地图);
}


非常感谢,这正是我想要的!!信息窗口正好落在我的标记上。有没有办法计算经度差,以便将信息窗口正好放在标记上方?最简单的解决方案是,将其称为“外部标记单击”。。谢谢你,如果你解释一下为什么你的代码可以工作,RokaIt会更好。