Gmaps4Rails : How to open the Infowindow of the single marker by default when the Google maps is loaded (without clicking on the marker)

最后都变了- 提交于 2019-12-10 10:08:03

问题


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 %>

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

Thanks for you help and support.


回答1:


Instead of

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

Try

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

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



来源:https://stackoverflow.com/questions/8213093/gmaps4rails-how-to-open-the-infowindow-of-the-single-marker-by-default-when-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!