I am trying to grab a users location via HTML5 and pass it to my rails controller.
I have the JavaScript below which calls .value on the element and sets it equal to the respective position. I would then like to submit these values through a hidden form field and pass it to my location controller so I can populate locations based on the users position. I know this has been done before and I have seen a few posts on it, but I have not had success.
navigator.geolocation.getCurrentPosition(GeoL);
function GeoL(position) {
document.getElementById('lat').value = position.coords.latitude;
document.getElementById('lon').value = position.coords.longitude;
}
<%= form_tag locations_path, :method=>'post' do %>
<%= hidden_field_tag 'lat', value = ''%>
<%= hidden_field_tag 'lon', value = ''%>
<%= image_submit_tag 'loc.png' %>
<% end %>
def create
"What goes here? Grab params? Is this the right action to send it to?"
end
I am currently getting the error you see in this screen shot below. I think my form may need some work, plus I need to add code in my controller to grab the values. As you can see a little lost, any advice would be great.