views:

26

answers:

2

I'm using the Google Maps Javascript API so that I can have someone put a marker on a map and then get the latitude and longitude from that to submit as part of a form. I know how to get the data from the Maps api just fine, but I can't figure out how to submit the javascript variables that I have to the rails form?

An event is called ever time the maps marker is moved, so at that point is there a way to send the lat and long variables back to hidden form fields in rails or something?

+1  A: 

Create some hidden lat and long fields in the form you want to submit then dynamically add values to the hidden fields, so when you submit the form, it will be included to the post variables

corroded
A: 

Do what corroded said by setting hidden fields with the values.

But rather than setting the hidden fields everytime a marker move event occurs, it will be more efficient to set the hidden fields once, when the form submission is triggered.

You should be able to wire up an event to read the marker position and set the fields accordingly.

SamStephens
Sorry I'm pretty new to javascript. How specifically would I do either corroded's solution or yours?
I'm not going to write the code for you, so let me know what parts of the solution you're having specific trouble with, and I can give you pointers, or point you at useful documentation.
SamStephens
$('hidden_latLong').value = mapCenter; That seemed to work for Corroded's solution. I think I know how to do your better solution too now. Thanks!