Reputation: 383
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.
Upvotes: 3
Views: 1521
Reputation: 41
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.
Upvotes: 3