Where can I find a list of all UK full postcodes including street name and their precise coordinates? They should be not like AB1, AB23 etc but AB1 2AA, AB23 5ZZ etc.>
As part of a freelance project in PyQt I've written an algorithm to get user input of postcode and return the street name for it. For anyone who's looking for an alternative to commercial systems, open-source and straightforward approach to this issue can use it freely.
I've written it in Python2.7 but can easily be replicated in the newer versions or in other languages.
import urllib
from urllib2 import urlopen
import json
try:
google_map_key = raw_input("please enter your google maps api key: ")
postcode = raw_input("Please enter a UK Postcode: ")
postcode = postcode.replace(" ", "")
url = "https://maps.googleapis.com/maps/api/geocode/json?address="+postcode+"&key="+google_map_key
response = urlopen(url)
json_obj = json.load(response)
counter = 0
if json_obj['status'] == 'OK':
for i in json_obj['results']:
for x in i['address_components']:
counter += 1
if counter == 2:
print ("Long street name: " + x['long_name'])
break
else:
print("No results found! Please enter a valid postcode or check your internet connection and google api key")
except:
print("Unhandle exception")