0

I was wondering if anyone is aware of any PHP scripts which maps a UK City onto a Post Code.

I have found something like this:

  case'North West England, England': {
    $postcode = 'M1 2NQ';
    break;
  }
  case'North East England, England': {
    $postcode = 'NE1 6AD';
    break;
  }
  case'South West England, England': {
    $postcode = 'EX1 3AX';
    break;
  }

But it only covers areas as you can see, rather than cities such as 'Manchester, Edinburgh' etc.

Any input would be greatly appreciated.

Thanks, AP

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • has i know uk post codes are based on latitudes and longitudes rather than cities or areas – Rinzler May 28 '12 at 09:12
  • I don't know much about the British postal system, but is there really only one code that applies to all of South West England? – deceze May 28 '12 at 09:12
  • 3
    It is possible of course to pick an arbitrarily central postcode for each city. However I think you might have to compile this yourself - most postcode databases available for the UK are commercial products, and (for the time being at least) this is not freely available data - it's copyrighted. – halfer May 28 '12 at 09:14
  • 1
    This was an example I found, I'm unsure how it chooses the postcode but the above postcodes relate to Manchester, Newcastle and Exeter (random locations within).... I think :s – Adam Parkin May 28 '12 at 09:15
  • Have you looked at the Ordnance Survey's Open Codepoint data which provides details of all UK postcodes - https://www.ordnancesurvey.co.uk/oswebsite/products/code-point-open/index.html – Mark Baker May 28 '12 at 09:16
  • @halfer - why does everyone forget that the Ordnance Survey provide a free postcode database? – Mark Baker May 28 '12 at 09:16
  • I used to work for a delivery company and we'd buy in the postcode data from one of the Royal Mail's licensed vendors. The postcodes came with all the addresses for each postcode and the longitude and lattitude. You'll find this difficult without the full data or an API you can query. – GrandMasterFlush May 28 '12 at 09:17
  • You can also Try this one looking at other alternatives http://stackoverflow.com/questions/9081233/how-to-get-geolocation-from-a-uk-postal-code – Rinzler May 28 '12 at 09:21
  • @MarkBaker - that's an excellent development. I didn't 'forget' that information, however - I simply wasn't aware of it. But for the benefit of accuracy, it _is_ the case that postcode data had for a long time in the UK been subject to crown copyright, for which one had to pay a license fee to obtain the data. I suspect they are now following the US model (postcode data was built using taxpayer's money, and so ought to be free) or perhaps an argument was made in favour of encouraging innovation. Either way, that must have happened in the last couple of years, I should think. – halfer May 28 '12 at 09:26
  • 1
    @halfer - about 3 yrs ago now... its only updated quarterly rather than monthly, requires a manual download, and the location data is Northings/Easting rather than lat/long.... but the conversion is straightforward and it's a good alternative to the costly PAF if you need data at the postcode level rather than the address level... I've been working on using it for reverse postcode lookup – Mark Baker May 28 '12 at 09:29

2 Answers2

1

You might think of using Google Map API

Roman Newaza
  • 11,405
  • 11
  • 58
  • 89
0

You can use the ONS Postcode Directory (ONSPD). You'd have to set up a database and import all the data, then build your application round it.

user2829228
  • 137
  • 2
  • 3