Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Last active December 31, 2015 16:29
Show Gist options
  • Select an option

  • Save cianclarke/8014436 to your computer and use it in GitHub Desktop.

Select an option

Save cianclarke/8014436 to your computer and use it in GitHub Desktop.
Geo Service
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