MySQL UK post code table with corresponding longitude and latitude






The PHP script on github




    php import.php postcodes.csv


    php import.php postcodes.csv echo > mysql_postcodes.sql



9 thoughts on “MySQL UK post code table with corresponding longitude and latitude”

  1. Hi Vixre,

    I am looking to use your postcode to postcode distance calculator on my start-up WordPress courier website.
    I have now downloaded the files and the PHP script on github from this site.

    Can you please tell me how to set this up on my WordPress website so that I can have a postcode to postcode distance calculator insert on a Page from where a visitor would input their pick-up and delivery postcodes and get a milage calculation on the page.

    Thanking you in anticipation,

    1. Hi Glenn, thanks for commenting.

      One way to implement a post code to postcode distance search would be to:

      1. Create an ajax call which posts the two postcodes to a php file.
      2. In the php file take the two postcodes, find their longitude and latitude points by doing a lookup in the table.
      3. Use the the haversine formula to calculate the distance between the two points.
      4. You could also do any cost calculations etc once the distance has been determined.
      4. Return the distance and anything else (e.g. costs incurred) back to the ajax function and write to a div with the results.

      Please note that this method does not take into account roads, it’s a simple ‘as the crow flies’ distance calculation. I have some code which does this but I need to go through it and write an article on how to use it.

      I hope this has shed some light on a possible way to approach the distance calculation.

  2. Thank you very much for your reply.
    This does indeed shed some light on a possible way to approach the distance calculation.

    When do you think your article on how to do this using your code will be available?

    Thank you once again.

  3. Actually that site you mention DOES have mysql tables as well as that they have a CSV including the MsSql you used.

    Note that the database gets updated and theirs an issue of duplicate records that need addressing!

  4. I wanted to implement complete list of United Kingdom potcodes so can any one help me how to find area, postcode including lattitude and langitude.

Leave a Reply
