In this example, we will build a web page that shows restaurants near the user's location. Similar to the earlier example, we will get the current location with the W3C Geolocation API, and mark it on a map rendered by the Google Maps API. Once the page is loaded and the location is marked on the map, we will perform an AJAX request to query MongoDB with the coordinates and get the location of the nearby restaurants (we will insert some sample data into the collection before hand):
1. Launch the mongo shell and switch to the
geolocation
database:$./mongodb/bin/mongo MongoDB shell version: 1.8.1 connecting to: test > use geolocation switched to db geolocation
2. Manually insert some sample data into a collection named
restaurants
(the location coordinates of the fictional restaurants should be close to your location):> db.restaurants.insert({name:"McDowells", serves: "Fast Food", "location": [23.755235, 90.375739]}) > db.restaurants...