Last active
August 29, 2015 14:22
-
-
Save stephenkeable-allies/2fb6a947a2ed17abd25d to your computer and use it in GitHub Desktop.
UK Geocoding with PostCoder Web in Node.js
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 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