Gmaps4Rails:如何在加载谷歌映射时(不单击该标记)默认打开单个标记的Infowindow

时间:2021-10-24 20:59:27

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?

我在rails应用程序中使用Gmaps4Rails加载谷歌映射。一切工作正常。我有一个标记,我想在加载谷歌映射时(不需要单击该标记)默认保持infowindow打开。请帮助我如何使用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 %>

This was the solution mentioned by apneadiving in How do I make an infowindow automatically display as open with Google-Maps-for-Rails

这是apneadiving所提到的解决方案,在如何使用Google-Maps-for-Rails自动显示一个infowindow

Thanks for you help and support.

谢谢你的帮助和支持。

1 个解决方案

#1


3  

Instead of

而不是

infowindow.open(Gmaps.map.map, marker);

infowindow.open(Gmaps.map。地图,标记);

Try

试一试

infowindow.open(Gmaps.map.map, marker.serviceObject);

infowindow.open(Gmaps.map。地图,marker.serviceObject);

I was also having trouble getting the infowindow to open and that seems to work for me.

我在打开infowindow时也遇到了麻烦,这对我来说似乎很有效。

#1


3  

Instead of

而不是

infowindow.open(Gmaps.map.map, marker);

infowindow.open(Gmaps.map。地图,标记);

Try

试一试

infowindow.open(Gmaps.map.map, marker.serviceObject);

infowindow.open(Gmaps.map。地图,marker.serviceObject);

I was also having trouble getting the infowindow to open and that seems to work for me.

我在打开infowindow时也遇到了麻烦,这对我来说似乎很有效。