Gmaps4Rails : 如何在加载谷歌地图时默认打开单个标记的信息窗口(不点击标记) [英] Gmaps4Rails : How to open the Infowindow of the single marker by default when the Google maps is loaded (without clicking on the marker)
问题描述
我在 Rails 应用程序中使用 Gmaps4Rails 来加载谷歌地图.一切正常.我有一个标记,我想在加载谷歌地图时默认保持信息窗口打开(不点击标记).请帮助我如何使用 Gmaps4Rails gem 实现这一目标?
I am using Gmaps4Rails in my rails application for loading google maps. Everything works fine. I have a single marker and I want to keep the infowindow open by default when the google map is loaded (without clicking on the marker). Please help me how to achieve this using Gmaps4Rails gem?
我已经尝试了以下代码片段,但它不起作用.
I have tried the following snippet of code but it doesn't work.
<% content_for :scripts do %>
<script type="text/javascript" charset="utf-8">
Gmaps.map.callback = function() {
if (Gmaps.map.markers.length == 1) {
var marker = Gmaps.map.markers[0];
var infowindow = marker.infowindow;
infowindow.open(Gmaps.map.map, marker);
<%#*alert("Gmaps info open");%>
}
}
</script>
<% end %>
这是 如何使用 Google-Maps-for-Rails 使信息窗口自动显示为打开状态
感谢您的帮助和支持.
推荐答案
代替
infowindow.open(Gmaps.map.map, 标记);
infowindow.open(Gmaps.map.map, marker);
试试
infowindow.open(Gmaps.map.map,marker.serviceObject);
infowindow.open(Gmaps.map.map, marker.serviceObject);
我也无法打开信息窗口,这似乎对我有用.
I was also having trouble getting the infowindow to open and that seems to work for me.
这篇关于Gmaps4Rails : 如何在加载谷歌地图时默认打开单个标记的信息窗口(不点击标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!