Created
August 12, 2016 00:34
-
-
Save lbrenman/71f6e395769abd29c446fb8f0871a692 to your computer and use it in GitHub Desktop.
Arrow Builder Custom API for Google Places
This file contains hidden or 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
| 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