Search code examples
ruby-on-railslistenergmaps4railsgmaps4rails2

Rails Listener in marker on Gmaps4rails2



I'm trying do add a listener in my markers but doesn't work in my view i have the BuildMap(<%= @hash.to_json %>);
my controller is

@hash = Gmaps4rails.build_markers(gon.transmitters) do |transmitter, marker|
    marker.lat transmitter.latitude
    marker.lng transmitter.longitude
    marker.json({ :id => "trm", :data => transmitter.id , :img => "http://www.clker.com/cliparts/B/B/1/E/y/r/marker-pin-google.svg"})
end

and in my js.coffee

@buildMap = (markers) ->
  handler = Gmaps.build 'Google'
  handler.buildMap { provider: {}, internal: {id: 'map'} }, ->
    markers = handler.addMarkers(markers)
    handler.bounds.extendWith(markers)
    handler.fitMapToBounds()
    for marker in markers
      google.maps.event.addListener marker, 'click', ->
        alert "hello" 
        true
      true

What i am doing wrong?
thanks in advance
edit: apneadiving where are you?!? :(


Solution

  • marker is a proxy object, simply replace:

    google.maps.event.addListener marker, 'click', ->
    

    with:

    google.maps.event.addListener marker.getServiceObject(), 'click', ->