HTML5 Geolocation In Rails

∥☆過路亽.° 提交于 2019-12-05 13:10:29

As i understand you, you would like to show locations based on the users position. That means you locate the user like you already did, write lat and lon into the hidden_form_fields and send this form via ajax to the index (!) action of your locations_controller (not the create action).

With geocoder the controller looks something like that:

@locations = Location.near([params[:lat], params[:lon]])
.
.
.
respond_to do |format|
 format.html {}
 format.js {}
end

Then you only have to insert your new @locations into your index view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!