1

my goal is simply list all the places within 20 KM from point A, Im using Google Maps API to help me with this

I use node.js/Express + mongoose for the backend part.

For example, If i live at Point A, and if I open up my phone, it would show all the list of places nearby my location which is Point A within 20 KM

How would I achieve this in the backend?

What are the condition should I pass to mongoose to find the list of places, or my approach is wrong?

Place.find({}, function(err, places) {
   res.json(places);
});
sinusGob
  • 4,053
  • 12
  • 46
  • 82

2 Answers2

0

Use Place Search - Nearby Search request for places within a specified area. You can refine your search request by supplying keywords or specifying the type of place you are searching for.

Here's a sample Nearby Search request:

https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters

Include rankby parameter to specifiy the order in which results are listed. Possible values are prominence, distance and location.

Here's a related SO ticket: Google Nearby places search

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
0

An alternative is to use Places API Web services.

You have 2 aptions to search 1) Nearby search returns complete information of each place but it returns up to 20 results on each query and if more places available, it returns a "next page" token.

url="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+lat+","+long+"&radius=" +radius+"&types=" + types + "&key=<PUT_YOUR_API_KEY_HERE>";

lat and long are your center coordinates. radius is measured in meters and is a value up to 50000. types is the type of Place you are searching according to this listing: https://developers.google.com/places/supported_types . Example: "atm"

2) Radar search that returns a reduced set of information of each place but it returns up to 200 on each query

url="https://maps.googleapis.com/maps/api/place/radarsearch/json?location="+lat+","+long+"&radius=" +radius+"&types=" + types + "&key=<PUT_YOUR_API_KEY_HERE>";

lat and long are your center coordinates. radius is measured in meters and is a value up to 50000. types is the type of Place you are searching according to this listing: https://developers.google.com/places/supported_types . Example: "atm"

You have more options to search, keyword & name appart from type. Keep in mind that you must specify at least one of them.

You can have your results on xml or json format.

Full definition of nearby and radar search is here: https://developers.google.com/places/web-service/search

Juan Pablo
  • 1,213
  • 10
  • 15