easteregg
easteregg

Reputation: 147

gmaps4rails open infowindow by default

I am on a rails v.3.1.11 app and using gmaps4rails gem. according to various examples I've seen, i tempt to doing the goal of the subject with this:

on the footer of my view (using haml):

= yield :scripts
:javascript
    Gmaps.map.callback = function(){
        console.log('callback');
        $(document).trigger('map:ready');
    }

then define the trigger on a coffee script file:

$(document).on 'map:ready', -> openInfoWindow()
openInfoWindow = ->
  for m in Gmaps.map.markers
    marker = m.serviceObject
    google.maps.event.addListener marker, "click" ->
      infowindow.open(map,marker)
    infowindow.open(map,marker)

but i have an error: Uncaught ReferenceError: object is not defined I made other attempts but I cannot figure out how to set the thing

Upvotes: 0

Views: 653

Answers (1)

David
David

Reputation: 1191

You can't use infowindow and map directly.

You have to use properties of the marker object(m in your code).

Try:

$(document).on 'map:ready', -> openInfoWindow()
openInfoWindow = ->
  for m in Gmaps.map.markers
    marker = m.serviceObject
    google.maps.event.addListener marker, "click" ->
      m.infowindow.open(marker.map, marker)
    m.infowindow.open(marker.map, marker)

hth

Upvotes: 1

Related Questions