Last active
February 20, 2017 16:31
-
-
Save SBejga/b49f3bbedf1e4f52c51f575a64574714 to your computer and use it in GitHub Desktop.
This file contains 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 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