UK Postcode to Long/Lat API

O.K, so apologies for not posting for a while, I have been soo busy, but I do have lots to write about so will probably be flooding the site with posts over the coming days!

But, some good news! I have decided to build my own UK postcode to Long/Lat api using opensource data so I can get around the Royal Mail's ridiculous ownership of this data. It's going to take a while, but am getting there slowly.

you can request a json response via cURL by using the below;

http://api.richardallen.co.uk/postcode/get.php?postcode=firstpartofpostcode

Which will respond with the below json;

  
{"postcode":"postcode","long":"52","lat":"0"}

This should provide details for all 1.7million ish post codes in the UK (excluding Northern Ireland at the moment). As you can see, it's not returning a long/lart response but a Easting/Northings location. This is causing me a few issues.

First, the data I have is from the UK's Ordinance Survey and is based on the Airy 1830 ellipsoid using the OSGB36 datam. Google Maps and GPS is based on WGS84, the difference between the two of these can be as much as 120 metres. (I won't bore you to death about this now, I'll write another post all about this tomorrow), so I need to convert the OSGB36 data into WGS84 without losing it's accuracy. Hopefully I can find a script online to do this, otherwise its lots of complex equations that I don't really have time to work out!

I'll clean this page up soon detailing how I created the api, will split out the navigational parts into a new post and create some clear api documentation, but before all of that I want to get it working!

Update

O.K, so now I have managed to figure out the lat/long details, almost there now!

I also need to return decimal places and not round up, looks like a DB issues, will figure it out later.

Show Comments