· 6 years ago · Dec 28, 2019, 07:44 AM
1const https = require('https');
2
3/* to get an API key you will need to create and link a free Google Cloud project
4 https://developers.google.com/places/web-service/get-api-key
5 You want to create an API key for the Google Maps --> Places API
6
7 To get the lat/long, open Google Maps, then click or double click on a place and you will see the lat/long
8 in the format needed. Just remove the space after the comma
9
10 API Documentation: https://developers.google.com/places/web-service/search#PlaceSearchRequests
11 */
12
13const apiKey = 'your_api_key_here';
14const locationLatLong = '33.765314,-84.142345'; // some place in Georgia. Must be lat/long
15const radiusInMeters = '304.8'; // 1,000 ft;
16const type = 'school'; // see https://developers.google.com/places/web-service/supported_types for a list of types
17
18const url = `https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${locationLatLong}&radius=${radiusInMeters}&type=${type}&key=${apiKey}`;
19
20https.get(url, (res) => {
21 res.setEncoding("utf8");
22 let text = '';
23 let payload;
24 res.on("data", data => {text += data});
25 res.on('end', () => {payload = JSON.parse(text); console.log(payload)});
26});