Last active
October 18, 2016 07:41
-
-
Save SBejga/6d1014b97907d372d982e55fba93178f to your computer and use it in GitHub Desktop.
reverse Geocoding example with typescript
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
{ | |
"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" | |
} | |
} |
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; | |
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); | |
}); |
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
Show hidden characters
{ | |
"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