I would like to query a table in rails using this query (found here ):
Select ID, Postcode, Lat, Lon,
acos(sin($lat)*sin(radians(Lat)) + cos($lat)*cos(radians(Lat))*cos(radians(Lon)-$lon))*$R As D
From MyTable
Where acos(sin($lat)*sin(radians(Lat)) + cos($lat)*cos(radians(Lat))*cos(radians(Lon)-$lon))*$R < $rad
(finds all points located within a certain radius of a given point)
The answer is to use GeoKit-Rails (or GeoKit-Rails3 ). Then your queries will look like this:
Store.find(:all, :origin => @somewhere, :within=>10)
or the Rails3 version:
Location.within(5, :origin => @somewhere)
where @somewhere
is a point ( [37.792,-122.393]
), zip, address, etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.