Skip to content

Instantly share code, notes, and snippets.

@stephenkeable-allies
Last active August 29, 2015 14:22
Show Gist options
  • Save stephenkeable-allies/2fb6a947a2ed17abd25d to your computer and use it in GitHub Desktop.
Save stephenkeable-allies/2fb6a947a2ed17abd25d to your computer and use it in GitHub Desktop.
UK Geocoding with PostCoder Web in Node.js
var https = require('https');
// This is a test API Key which works for the postcode NR14 7PZ
// Get your API Key from www.alliescomputing.com/postcoder/sign-up
var api_key = 'PCW45-12345-12345-1234X';
var postcode = 'NR147PZ';
var headers = {
'Content-Type': 'application/json'
};
var options = {
host: 'ws.postcoder.com',
path: '/pcw/'+api_key+'/position/uk/' + encodeURIComponent(postcode),
method: 'GET',
headers: headers
};
var req = https.request(options, function(res) {
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
var responseObject = JSON.parse(responseString);
console.log("Coordinates: "+responseObject[0].latitude + "," + responseObject[0].longitude);
});
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment