I am working on a google map application, to display the items that are listed in the selected rectangular area. Below image give you some understanding.
Based on the co-ordinates (topLeft,bottomRight), i am running bounding box query to find the items in mongo db. But it always returns the this error when running the box queries
Error: $box needs 2 fields (bottomLeft,topRight)
I know that i have passed topLeft,bottomRight points instead the mongo expected one (bottomLeft,topRight).
How do I calculate the bottomLeft,topRight values based on the co-ordinates from Google Maps?
This is the actual value i got trouble with
bound_box = [[80.22050443383796, 13.051049734963444], [80.2393871853028, 13.043106313697518]]]
and ruby code for finding bounding box values in mongo db
items = Item.where(:loc => {"$within" => {"$box" => [bound_box]}},
:category => BSON::ObjectId(cat), :sub_category => BSON::ObjectId(sub)).order_by(:created_at => :desc).skip(@current_page * 5).limit(5).paginate
this is the line giving problem
items = Item.where(:loc => {"$within" => {"$box" => [bound_box]}})
which is similar to the mongodb query
db.items.find({"loc" : {"$within" : {"$box" : bound_box}}})