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.
Is that possible? I'm using coffeescript and slim-lang
my helper method, located in application_helper.rb:
def get_station(location)
type = not relevant
key = not relevant
radius = 5000
url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{location}&radius=#{radius}&type=#{type}&key=#{key}"
data = JSON.load(open(url))["results"][0]["name"]
end
the coffeescript part in my view (.slim template):
set_location = ->
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(setLocation);
setLocation = (position) ->
coords = position.coords.latitude + ", " + position.coords.longitude;
Threads I reviewed before posting: