使用Google-Maps-for-Rails Gem如何找到指定距离内指定距离的点?

我想知道是否可以使用Google-Maps-for-Rails gem来查找保存在数据库中的点列表,这些点位于给定点的指定半径范围内。 例如,我如何找到数据库中距离自由女神像20英里范围内的所有点。

除非我错过了,否则我在文档中找不到任何内容。

谢谢你的期待。

我认为Google Maps for Rails不会开箱即用。 我最终使用Google Maps for Rails来处理生成地图,并使用Geocoder gem进行地理编码和确定我的数据点范围。

有了这两个gem,在我的模型中我有:

class Store < ActiveRecord::Base acts_as_gmappable private def gmaps4rails_address "#{address_line_1}, #{self.city}, #{self.region}, #{self.postal_code}, #{self.country}" end end 

在我的控制器中,我有:

def指数

 if params[:search] @stores = Store.near(params[:search], 20) @json = @stores.to_gmaps4rails else @stores = Store.all @json = @stores.to_gmaps4rails end respond_to do |format| format.html # index.html.erb format.json { render json: @stores } end 

结束

这似乎工作得很好,但我会稍微留下这个问题,以防有更好的答案。