Reputation: 3907
In ror, suppose I have a list of geo referenced data in my database (each record have latitude and longitude column) what is the best way to implement search according-to-distance function?
I am aware of geokit for ruby. But I am looking for other suggestions. If it is platform dependent, I plan to use heroku as deployment platform.
Upvotes: 0
Views: 704
Reputation: 23344
Use the gem Geocoder.
As specified in documentation -
Geocoder is a complete geocoding solution for Ruby. With Rails it adds geocoding (by street or IP address), reverse geocoding (find street address based on given coordinates), and distance queries. It's as simple as calling geocode on your objects, and then using a scope like Venue.near("Billings, MT").
With geocoded objects you can do things like this:
if obj.geocoded?
obj.nearbys(30) # other objects within 30 miles
obj.distance_from([40.714,-100.234]) # distance from arbitrary point to object
obj.bearing_to("Paris, France") # direction from object to arbitrary point
end
Upvotes: 1
Reputation: 16619
have you checked rubygeocoder gem ,
read this about the distance queries
Following is a great screencast by ryan
Upvotes: 1