|
@@ -0,0 +1,20 @@ |
|
|
|
|
|
# Geocode a postcode & find councils/wards via uk-postcodes.com API |
|
|
|
|
|
|
|
|
|
|
|
require 'rubygems' |
|
|
|
|
|
require 'json' |
|
|
|
|
|
require 'rest_client' |
|
|
|
|
|
require 'pp' |
|
|
|
|
|
|
|
|
|
|
|
postcode = "SW1A 0AA" |
|
|
|
|
|
endpoint = "http://www.uk-postcodes.com/postcode/" |
|
|
|
|
|
|
|
|
|
|
|
result = RestClient.get(endpoint + postcode.gsub(/ /, '') + '.json') |
|
|
|
|
|
|
|
|
|
|
|
result_ary = JSON.parse(result) |
|
|
|
|
|
|
|
|
|
|
|
puts "Lat:" + result_ary['geo']['lat'].to_s |
|
|
|
|
|
puts "Lng:" + result_ary['geo']['lng'].to_s |
|
|
|
|
|
puts "District: " + result_ary['administrative']['district']['title'] |
|
|
|
|
|
puts "Ward: " + result_ary['administrative']['ward']['title'] |
|
|
|
|
|
|
|
|
|
|
|
pp result_ary |