Created
July 17, 2012 16:48
-
-
Save adrianshort/3130535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post | |
include MongoMapper::Document | |
key :title, String | |
key :url, String | |
key :author, String | |
key :summary, String | |
key :content, String | |
key :published, Time | |
key :loc, Hash # { lng, lat } | |
timestamps! | |
ensure_index [[:loc, '2d']] | |
belongs_to :feed | |
EARTH_RADIUS_M = 6378000 | |
def self.near(lat, lng, radius_m) | |
all( | |
:loc => { | |
'$nearSphere' => [ lng, lat ], | |
'$maxDistance' => radius_m / EARTH_RADIUS_M | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment