Reputation: 11503
How can I store the geolocation (longitude and latitude) of a website user in Rails? (Ruby 1.9.2 + Rails 3)
Ideally I'd like to hook into the HTML5 geolocation feature instead of using an IP based lookup as I'd like to give the user control over sharing their location using the built in prompt/notifcation. But as this runs on the browser client side I am not sure how I can connect/process the data on the server side in Rails. Any idea/best-practice for getting and saving the geolocation in Rails?
Upvotes: 1
Views: 779
Reputation: 91
Convert the lat and long decimal degrees to JSON and send to server via AJAX (or you could start by just using hidden fields), and store them in a latitude and a longitude column in the database.
If you want to do more than just store the data, use a spatially-enabled database such as Postgres with PostGIS to store geolocations allowing complex spatial functions and queries on the gathered data. To facilitate doing this in rails look at the GeoRuby and spatial_adapter gems.
Upvotes: 1