location finder by typing your post code (UK)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I wonder if you could advice me on the best solution.

I will receive from my client a raw data with locations of their
stores, which probably would look like this:
"B&Q, Industrial Park, Huntingdon, Cambridgeshire, CB23 2KK, 01480

What I need to do is add to the website a location finder by typing a
postcode. Let's say I type "CB4 1JT" or "Cambridge" where I live and I
want to display number of nearest stores.

Ideally I would like to achieve similar result to this one:

What would be the best approach to implement solution like that? Do I
need to buy off-shelf solution? Which one, from your experience, is
the best. Obviously it must support PHP.

Thanks a million,

Re: location finder by typing your post code (UK)

Richard wrote:
Quoted text here. Click to load it
Sounds like you need a database of postcodes and their latitude and  
longitude to me..

After that its all just maths innit?

First hit on google


Looks exactly what you want. PHP and Mysql as well! Who could ask for  

Re: location finder by typing your post code (UK)

Richard emailed this:
Quoted text here. Click to load it

Hi Richard,

It just so happens I have expertise in development in exactly this field,  
though not using PHP for it. In July of this year, I gave some advise to  
someone trying to achieve almost exactly what you are trying to do, for UK  
cinema locations, although they were intending to use a UK postcode and  
not a place name as well, and had an almost non-existent budget.

The advise I gave them was in an email which I will append below but I  
don't have time to tailor it for you, so bear in mind it will be in  
reference to the other project.

If you intend to develop it yourself and have a budget that can include  
the license for the Royal Mail's PAF (postcode address file) -see appended  
email for detailed info.- then that will be the most efficient solution.  
If you're looking for an off-the-shelf solution, you should look for some  
kind of GIS (Geographic Information Software) solution, of which many  
exist but are expensive, and possibly overkill for what you are trying to  
do. The web bot solution (in the appended email) was mentioned primarily  
because they guys I was advising had no budget, and is a much less  
efficient (but free) solution as the email explains.

When I was doing postcode/location development, 5 years ago, there was no  
Web Service that provided UK postcode to location data. I would be  
surprised if that did not now exist, but in what form I know not and there  
may be no such service that will work for you. I just did a web service  
search and this may be a winner!! The service details are as follows, url  
at bottom.

Get UK Postcode,Town,County and Validate UK Address

The following operations are supported. For a formal definition, please  
review the Service Description.

  * GetUKLocationByCounty
  Get UK town,Postcode and County by full /partial County

  * ValidateUKAddress
  Validate UK address,Use First Section of Poscode for Postcode atribute

  * GetUKLocationByPostCode
  Get UK town,Postcode and County by Postcode(First Section of Post Code)

  * GetUKLocationByTown
  Get UK town,Postcode and County by full /partial Town

See this URL:

Other more appropriate newsgroups you could get help from are:


There is also a dedicated UK postcode discussion mailing list, but I no  
longer have the details and a quick web search did not find it. If you can  
find it with a web search, it would be a valuable info. resource from  
people who do this kind of thing professionally. Key words that might  
source it are: postcode gis geography (and synonyms) mailing list, etc..  
People in the newsgroups above may know the subscribe details.

I'll gladly answer more questions if you have any. Post an email address  
and I'll contact you by email.

Email appended below.



Richard Note: If you can, it would probably best to use UK OS coordinates.  
You'll need to be doing distances between locations, and with UK OS coords  
you can just use Pythagoras (contact me for more info.), long/lat is a  
more complex calculation.

Advise on postcode to cinema location project.

Firstly I should say I am unsure exactly what you want to achieve, so had  
better spell out the impression I've got, which is:

In order to tell which cinema is nearest to a particular user, you want to  
get their long/lat from their postcode so that you can determine which is  
their nearest cinema. Alf also said you had tried using Google Maps but  
that it was unreliable when doing this. Is that correct?

Here are some notes and methods that will hopefully help.

The data can be bought in the form of a massive csv file, called the  
'Postcode Address File' but known as the PAF, url below (though a web  
search will provide you with more info.). UK wide coverage is pretty  
expensive. I have a copy (from an old project) which is 5 years out of  
date, and I no longer have a license for it. The PAF has way more info.  
than just coordinate data, but that includes UK OS (Ordinance Survey)  
coordinates and long/lat coordinates. For the data I needed which was just  
the OS coords and street names for each unique postcode, I added just that  
data to a database table (initially PostGreSQL, later MySql). This method  
of looking up OS coords for a specific postcode was very quick, very  
effective, and highly reliable.

Note: I just looked at the field names of the PAF data from the URL below  
and coordinate data is not listed, also the number of fields is very few  
in comparison to the file I had, so the product I had may have been  
changed into *maybe* several different products. BUT I am certain the  
Royal Mail's 'postcode to location coordinates' data will be for sale in a  
way that allows it to be added to your own database.

Look here...
but search the web too.

However I understand the budget may not be up to buying the data and that  
you were unsatisfied with Google Maps. I've not used/played with Google  
Maps but understand it has an API available. Were you using the API to  
retrieve coordinate data from UK postcodes?

One method that the UK OS and long/lat data could be retrieved for free  
would be by writing a web bot to get the data from a UK website called  


I have experience of writing such a bot, and have just had a play with the  
site capturing all data in and out of my network adapter with WinDump (a  
bit of free software you'll need if writing a bot like this). Here's how  
it could be done.

i) Simulate a web request on streetmap by sending the site a POST (not  
GET) header with the postcode you require in the form and all formatted as  
if someone had just entered the postcode in the site's search form.

ii) streetmap will respond by returning to you a webpage. The header of  
this has a field called 'location', which is how a site tells a browser  
what location to display in the 'location bar'. In streetmap's case this  
actually has the UK Ordinance Survey coordinates in it. Here's the  
location header data I got back from the query on my own postcode 'EC1V 4JY':


Near the start you can see 'x=531681&y=182358' which is the OS coords of  
my flat. NOTE: UK OS coordinates can be 7 figures which is accurate to 10  
metres. The data above is 6 figures, accurate to 100 metres. This is  
because a UK postcode may reference as many as 10 addresses, which could  
be along a street, so it can not be made accurate enough to warrant the  
use of 7 figured OS coords.

If you use UK OS coords, you've now got the data.

iii). If you need long/lat, you can do the following to get it from  
streetmap. However algorithms for converting UK OS coords to long/lat  
coords exist, but I believe these to be quite complex.

On the web page that streetmap returns from a postcode search, there is a  
link, labeled as "Click here to convert/measure coordinates". This link  
can be retrieved from the webpage returned by your original 'POST'  
request. You just need to 'GET' that URL, in another simulated webpage  
request, and streetmap will return a webpage with all the coordinate data  
you could want for the postcode. Click the URL below to see the results  
for my postcode.


Nice huh !!

iv) Finally you just need to write a small parser to retrieve whatever  
coordinate data you want (presumably lat/long) from that page.

This web bot method for your needs is quite sweet I think, but has one  
flaw. If streetmap.co.uk goes down so does your ability to get the data.  
However I've been using streetmap regularly for 8 years and don't ever  
remember it going down.

When I was writing bots to get web data, I used a bit of open source  
software called HTML Tidy. Any web pages returned to me I ran through  
Tidy, which converted the pages from HTML to XML (even very badly  
formatted HTML pages). Then I used XSLT queries to extract whatever data I  
wanted from the XML version of the webpages, resulting in nice XML  
outputting for the data I needed.

You could write a Web Service to get the coordinate data from streetmap  
for any postcode that you supply the web service as input. This could be  
quite an effective way of doing it, especially as you can probably host  
the web service on the same server that hosts your database.

Please give me some feedback on all this, with details of exactly what you  
want to achieve, I may have other helpful info. that hadn't occurred to me  
when writing this. Hope this helps.

Re: location finder by typing your post code (UK)

Quoted text here. Click to load it

It's not a UK dedicated postcode mailing list at all, it's a dedicated GIS  
mailing list, but members have postcode to location expertise: See here:



Re: location finder by typing your post code (UK)

Quoted text here. Click to load it

To that end, ESRI's ARCGISOnline.com is a freebie that has some interesting  
And if you're willing to pony up the bucks, they are *great* at tech  
supporting you.

The web bot solution (in the appended email) was mentioned primarily
Quoted text here. Click to load it

Re: location finder by typing your post code (UK)

Quoted text here. Click to load it

to anyone that wants it i have a 4 year old 42k UK xml file, (even the
tinyest village):
<?xml version="1.0" encoding="iso-8859-1" ?>
  <!-- Table uk_towns -->
        <town_name>a chill</town_name>
        <proper_town_name>A' Chill</proper_town_name>
and somewhere else about half a million postcodes, street names etc..
of equal age hanging around somewhere which were got using bot to
scour various sites and piece it all together (there are many more
than this but that was enough to get things working).
There are also many sites that as part of the sign up process they
query the PAF data they have bought, you could take 10 of them and
round robin your queries live cascading through them, but use cURL and
get the images as well, plus cookies or someone will see you.
You can do the same using the headers of sites like google maps, m$
and others - they save you the bother of downloading the actual page
to strip out the data you want. The postcodes were validated using UK
standard format to check for O instead of 0 etc...

The algorithm for finding the first x places near to a postcode does
lead to funnies when youre dealing with 2 towns across an estuary.
You will also have a database with hundreds of stores maybe, remember
to use LIMIT 10 to return only the 10 nearest ones within the right
lat/long range range, and done use LONG for your longditude column
name - I actually did that cos I was inexperienced in SQL!!

If you return your results in XML you can offer a webservice to others
in your position as well as solving your app needs, and can use AJAX
to update a div, or transform using FOP to PDF, ODF, CSV etc... RTF
(create in word with placeholder content, and manual page breask and
swop that for php variables, or use openoffice macro)and XLS (Biff
library). You can also "pre-unzip" the ODF and use php to change the
content.xml file and rezip with metadata on the fly.

Re: location finder by typing your post code (UK)

Richard wrote:

Quoted text here. Click to load it

Here's a link to my own work on postcodes. It supports basic postcode
parsing/validating for the UK, most of Western Europe, plus several other
countries, plus for the UK only: district-accuracy postcode positioning,
distance calculations and searching.


Unsupported -- don't ask me for help using it.

Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 1 day, 9:21.]

                    It'll be in the Last Place You Look

Re: location finder by typing your post code (UK)

While the city slept, Toby A Inkster (usenet200707@tobyinkster.co.uk)
feverishly typed...

Quoted text here. Click to load it

Ohhhhh.... now where was this when I was trying to figure all this out a few
months ago?? ;-)

An excellent set of data and routines sir! :-)


Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. nigel@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"

Site Timeline