title: Pass HTML5 geolocation to the controller
body: <p>I want to get the user's coordinates using HTML5 Geolocation and send them to a helper method.
  Geocoder gem is not an option because the IP geolocation is not accurate enough for my application. </p>
  
  <p>Is that possible?
  I'm using coffeescript and slim-lang</p>
  
  <p>my helper method, located in application_helper.rb:</p>
  
  <pre><code>  def get_station(location)
      type = not relevant
      key = not relevant
      radius = 5000
      url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{location}&amp;radius=#{radius}&amp;type=#{type}&amp;key=#{key}"
      data = JSON.load(open(url))["results"][0]["name"]
    end
  </code></pre>
  
  <p>the coffeescript part in my view (.slim template):</p>
  
  <pre><code>  set_location = -&gt;
      if (navigator.geolocation)
        navigator.geolocation.getCurrentPosition(setLocation);
  
    setLocation = (position) -&gt;
      coords = position.coords.latitude + ", " + position.coords.longitude;
  </code></pre>
  
  <p>Threads I reviewed before posting:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/8609030/get-rails-view-helper-methods-inside-coffeescript">Get rails view helper methods inside coffeescript</a></li>
  <li><a href="https://stackoverflow.com/questions/28202271/html5-geolocation-in-rails">HTML5 Geolocation In Rails</a></li>
  <li><a href="https://stackoverflow.com/questions/17705791/a-rails-app-which-gets-users-location-using-html5-geolocation-and-saves-to-data">A rails app which gets users location using HTML5 geolocation and saves to data base</a></li>
  <li><a href="https://stackoverflow.com/questions/9758416/storing-html5-geolocation-data">Storing HTML5 geolocation data</a></li>
  <li><a href="https://github.com/joofsh/geofsh" rel="nofollow noreferrer">https://github.com/joofsh/geofsh</a> </li>
  </ul>