I was wondering if there are any examples that consist on basic geolocation input and database retrieval of given inputs within a certain area, preferably the user’s current location.
I was wondering if there are any examples that consist on basic geolocation input
Share
Here’s a quick overview of geospatial queries in MongoDB:
You have to insert location information in your collection via 2D array
Set up a geospatial indexes on the collection by indicating the location field with “2d” option.
Now the collection will have an index which all geospatial queries will be done against.
To query for locations nearby a point (i.e. the user’s current location), use the find() command with
$nearoperand on the location field giving the point coordinates (i.e. 100, 100.)To find users current location, you would need higher level application support to get the user’s current information.
For more information:
MongoDB documentation:
http://www.mongodb.org/display/DOCS/Geospatial+Indexing
The
$nearoperator: http://docs.mongodb.org/manual/reference/operators/#_S_near