Skip to content

Instantly share code, notes, and snippets.

@unkleara
Last active December 26, 2015 06:49
Show Gist options
  • Save unkleara/7110767 to your computer and use it in GitHub Desktop.
Save unkleara/7110767 to your computer and use it in GitHub Desktop.
mongdb/mongoid geospatial queries
location = params[:query][:location]
radius = params[:query][:radius]
@items = Item.where({:'origin.coordinates' => { "$within" => { "$centerSphere" => [ location, (radius.fdiv(3959) )]}}})
T controller
@t = Location.where({:'origin.coordinates' => {"$within" => {"$centerSphere" => [origin, (oradius.fdiv(3959))]}}, '$and' => [{:'destination.states'.in => [state]}, "$or" => {:'destination.coordinates' => {"$within" => {"$centerSphere" => [dest, (dradius.fdiv(3959))]}}}]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment