|
@@ -10,5 +10,17 @@ class Post |
|
|
key :loc, Hash # { lng, lat } |
|
|
key :loc, Hash # { lng, lat } |
|
|
timestamps! |
|
|
timestamps! |
|
|
|
|
|
|
|
|
|
|
|
ensure_index [[:loc, '2d']] |
|
|
|
|
|
|
|
|
belongs_to :feed |
|
|
belongs_to :feed |
|
|
|
|
|
|
|
|
|
|
|
EARTH_RADIUS_KM = 6378.0 |
|
|
|
|
|
|
|
|
|
|
|
def self.near(lat, lng, radius_km) |
|
|
|
|
|
all( |
|
|
|
|
|
:loc => { |
|
|
|
|
|
'$nearSphere' => [ lng, lat ], |
|
|
|
|
|
'$maxDistance' => radius_km / EARTH_RADIUS_KM |
|
|
|
|
|
}) |
|
|
|
|
|
end |
|
|
end |
|
|
end |