Skip to content

Instantly share code, notes, and snippets.

@jeroenroodnat
Created March 1, 2011 19:08
Show Gist options
  • Save jeroenroodnat/849669 to your computer and use it in GitHub Desktop.
Save jeroenroodnat/849669 to your computer and use it in GitHub Desktop.
Mongo Geonear with Mongoid rough hack
query = BSON::OrderedHash.new.tap do |query|
query["geoNear"]="locations"
query["near"] = lon_lat
end
lon,lat =lon_lat
query = Location.collection.db.command(query)['results'].sort_by do |r|
r['distance'] = Haversine.distance(lat,lon,r['obj']['lon_lat'][1],r['obj']['lon_lat'][0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment