# YM4R GM Javascript events?

**URL:** <https://www.ruby-forum.com/t/ym4r-gm-javascript-events/105345>\
**Category:** Rails\
**Created:** [May 29, 2007, 4:37am UTC](https://www.ruby-forum.com/t/ym4r-gm-javascript-events/105345 "2007-05-29T04:37:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpacheco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/dfb087/32.png) [@hpacheco](https://www.ruby-forum.com/u/hpacheco)\
**Post date:** [May 29, 2007, 4:37am UTC](https://www.ruby-forum.com/t/ym4r-gm-javascript-events/105345/1 "2007-05-29T04:37:42Z")

</div>

Hi all,

I have added a GEvent to a google map with a JS calback and it works  
fine, but I do need to get some way of returning the values to rails,  
so I can add the new marker to an array.

For that, I need some kind of listener, call a ruby function,  
something like that.

The code is as follows:

def index  
@map = GMap.new(“map\_div”)  
@map.control\_init(:large\_map =\> true)  
@map.center\_zoom\_init ([59.91106, 10.72223],16)  
@map.overlay\_init(GMarker.new([59.91122, 10.72217], :title =\>  
“1.1”))

@map.event\_init(@map,:click,“function(overlay,point)  
{  
if (overlay)  
{  
map.removeOverlay(overlay);  
document.getElementById(“latitude”).value=null;  
document.getElementById(“longitude”).value=null;  
}  
else  
{  
map.addOverlay(new GMarker(point));  
document.getElementById(“latitude”).value=point.y;  
document.getElementById(“longitude”).value=point.x;  
}  
}”)

end

Thanks in advance,  
hugo
