Last active
December 31, 2015 16:29
-
-
Save cianclarke/8014436 to your computer and use it in GitHub Desktop.
Geo Service
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 http = require('http'); | |
| exports.latlong = function(params, cb) { | |
| var url, | |
| address = params.address, | |
| data = ''; | |
| url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + | |
| address + '&sensor=false'; | |
| http.get(url, function(res) { | |
| if (res.statusCode !== 200) { | |
| return cb(null, "0,0"); | |
| } | |
| res.setEncoding('utf8'); | |
| res.on('data', function (chunk) { | |
| data += chunk; | |
| }); | |
| res.on('end', function() { | |
| var jsonRes = JSON.parse(data), | |
| response; | |
| if (jsonRes.status === 'OK') { | |
| response = jsonRes.results[0].geometry.location.lat + ',' + jsonRes.results[0].geometry.location.lng; | |
| return cb(null, response); | |
| } else { | |
| return cb(null, '0,0'); | |
| } | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment