-
-
Save mrtonyhuynh/35681731db3abda06e8c to your computer and use it in GitHub Desktop.
Use the Google Places API with node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.randeats = function(req, res){ | |
var key = req.query.key; | |
var location = encodeURIComponent(req.query.location); | |
var radius = 16000; | |
var sensor = false; | |
var types = "restaurant"; | |
var keyword = "fast"; | |
var https = require('https'); | |
var url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?" + "key=" + key + "&location=" + location + "&radius=" + radius + "&sensor=" + sensor + "&types=" + types + "&keyword=" + keyword; | |
console.log(url); | |
https.get(url, function(response) { | |
var body =''; | |
response.on('data', function(chunk) { | |
body += chunk; | |
}); | |
response.on('end', function() { | |
var places = JSON.parse(body); | |
var locations = places.results; | |
var randLoc = locations[Math.floor(Math.random() * locations.length)]; | |
res.json(randLoc); | |
}); | |
}).on('error', function(e) { | |
console.log("Got error: " + e.message); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment