Skip to content

Instantly share code, notes, and snippets.

@SBejga
Last active October 18, 2016 07:41
Show Gist options
  • Save SBejga/6d1014b97907d372d982e55fba93178f to your computer and use it in GitHub Desktop.
Save SBejga/6d1014b97907d372d982e55fba93178f to your computer and use it in GitHub Desktop.
reverse Geocoding example with typescript
{
"name": "3_tsconfig",
"version": "1.0.0",
"description": "",
"main": "old.js",
"scripts": {
"demo": "tsc && node build/js/reverseGeo.js 'Stuttgart, Germany'"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^6.0.45"
},
"dependencies": {
"request": "^2.75.0"
}
}
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;
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);
});
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"removeComments": true,
"typeRoots": [
"node_modules/@types"
],
"outDir": "build/js",
"inlineSourceMap": true
},
"exclude": [
"node_modules"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment