Skip to content

Instantly share code, notes, and snippets.

@lbrenman
Created August 12, 2016 00:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lbrenman/71f6e395769abd29c446fb8f0871a692 to your computer and use it in GitHub Desktop.
Arrow Builder Custom API for Google Places
var Arrow = require('arrow');
var request = require('request');
var apikey = '<YOUR GOOGLE PLACES API KEY>';
var baseurl = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?radius=500&type=restaurant&key='+apikey+'&location=';
var location = '-33.8670522,151.1957362'
var Places = Arrow.API.extend({
group: 'places',
path: '/api/places',
method: 'GET',
description: 'return google places based on lat/lon',
parameters: {
lat: {description:'latitude of the mobile user'},
lon: {description:'longitude of the mobile user'},
},
action: function (req, resp, next) {
//Only accept GET
if(req.method==="GET") {
// console.log("Lat = "+req.params.lat);
// console.log("Lon = "+req.params.lon);
request(baseurl+req.params.lat+','+req.params.lon, function (error, response, body) {
if (!error && response.statusCode == 200) {
// console.log(body);
resp.send(body);
next();
} else {
resp.response.status(500);
resp.send({"error": "Places error, try again"});
next(false);
}
})
} else {
resp.response.status(500);
resp.send({"error": "only GET supported"});
next(false);
}
}
});
module.exports = Places;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment