Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正在侦听google.maps.InfoWindow类的domready事件_Javascript_Google Maps - Fatal编程技术网

Javascript 正在侦听google.maps.InfoWindow类的domready事件

Javascript 正在侦听google.maps.InfoWindow类的domready事件,javascript,google-maps,Javascript,Google Maps,所以,我正在尝试将谷歌地图添加到我的网页。当你点击地图上的一个标记时,我想在弹出的气泡中添加一个表单 API文档说domready “将包含信息窗口内容的附加到DOM时,将触发事件。如果动态生成信息窗口内容,您可能希望监视此事件。” 我如何聆听这一事件 这就是问题所在。我自己刚刚解决了一个类似的问题。要侦听domready事件,请使用以下语法: infoWindow = new google.maps.InfoWindow(); google.maps.event.addListener(inf

所以,我正在尝试将谷歌地图添加到我的网页。当你点击地图上的一个标记时,我想在弹出的气泡中添加一个表单

API文档说domready

“将包含信息窗口内容的附加到DOM时,将触发事件。如果动态生成信息窗口内容,您可能希望监视此事件。”

我如何聆听这一事件


这就是问题所在。

我自己刚刚解决了一个类似的问题。要侦听domready事件,请使用以下语法:

infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(infoWindow, 'domready', function() {
      // whatever you want to do once the DOM is ready
});

google.maps.event.addListener()事件等待infowindow HTML结构“domready”的创建,然后再应用infowindow定义的样式

我使用过这个例子:

google.maps.event.addListener(infowindow, 'domready', function() {

   // Reference to the DIV which receives the contents of the infowindow using jQuery
   var iwOuter = $('.gm-style-iw');
   var iwBackground = iwOuter.prev();

   // Remove the background shadow DIV
   iwBackground.children(':nth-child(2)').css({'display' : 'none'});

   // Remove the white background DIV
   iwBackground.children(':nth-child(4)').css({'display' : 'none'});

});
然后

结果:

参考:


谢谢

,但这只适用于我手动创建的信息窗口。如果我没有(比如使用Fusion表来生成它们)会怎么样?是否可以在这里获得px中的infowindow x和y位置?我使用相同的方法来定制infowindow。这是相当成功的,但是在转换到格式化版本之前,有时会有一个简单的窗口。有没有办法克服这个问题?我尝试过设置超时,但即使超时1秒,也只能部分解决问题。如果我超过这个时间,我想用户会放弃期待会发生什么,特别是当鼠标在地图上移动时,鼠标悬停事件已经有500毫秒的超时时间来阻止多个信息窗口打开。我在我的项目中检查了它,但我也看到了问题,尽管如此,我认为这并没有什么大问题,但我会对此进行研究。
google.maps.event.addListener(infowindow, 'domready', function() {

   // Reference to the DIV which receives the contents of the infowindow using jQuery
   var iwOuter = $('.gm-style-iw');
   var iwBackground = iwOuter.prev();

   // Remove the background shadow DIV
   iwBackground.children(':nth-child(2)').css({'display' : 'none'});

   // Remove the white background DIV
   iwBackground.children(':nth-child(4)').css({'display' : 'none'});

});
.gm-style-iw {
   width: 350px !important;
   top: 0 !important;
   left: 0 !important;
   background-color: #fff;
   box-shadow: 0 1px 6px rgba(178, 178, 178, 0.6);
   border: 1px solid rgba(72, 181, 233, 0.6);
   border-radius: 2px 2px 0 0;
}