【发布时间】:2016-09-12 17:18:50
【问题描述】:
我想使用 HTML5 Geolocation 获取用户的坐标并将它们发送到辅助方法。 地理编码器 gem 不是一个选项,因为 IP 地理定位对于我的应用程序来说不够准确。
这可能吗? 我正在使用 coffeescript 和 slim-lang
我的辅助方法,位于 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
我认为的咖啡脚本部分(.slim 模板):
set_location = ->
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(setLocation);
setLocation = (position) ->
coords = position.coords.latitude + ", " + position.coords.longitude;
发帖前我查看过的主题:
【问题讨论】:
标签: ruby-on-rails ajax html view geolocation