Skip to content

Instantly share code, notes, and snippets.

@SBejga
Last active February 20, 2017 16:31
Show Gist options
  • Save SBejga/b49f3bbedf1e4f52c51f575a64574714 to your computer and use it in GitHub Desktop.
Save SBejga/b49f3bbedf1e4f52c51f575a64574714 to your computer and use it in GitHub Desktop.
var request = require('request');
var reverseGeocode = function(locationName, callback) {
request({
uri: "http://nominatim.openstreetmap.org/search?format=json&q="+locationName,
json: true
}, function(err, response, body) {
if (err) { return callback(err, null); }
else {
if (body && body.length) {
return callback(null, body[0])
} else {
return callback("response is no array", null);
}
}
});
}
var param = process.argv[2];
if (!param) {
console.log('No parameter. Add location as parameter string (e.g. "Stuttgart, Germany")');
process.exit();
}
reverseGeocode(param, function(err, data) {
if (err) {
console.log("Error: ", err);
return;
}
var result = {importance: data.importance, type: data.type, lat: data.lat, lon: data.lon};
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment