我想使用此查询(找到here)查询rails中的表:
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
(找到位于给定点的某个半径内的所有点)
答案 0 :(得分:1)
答案是使用GeoKit-Rails(或GeoKit-Rails3)。那么您的查询将如下所示:
Store.find(:all, :origin => @somewhere, :within=>10)
或Rails3版本:
Location.within(5, :origin => @somewhere)
其中@somewhere
是一个点([37.792,-122.393]
),zip,地址等。