Hi,

Anyone know of a module/service that can calculate the distance between two postal codes?

I'm working on a personals app at the moment, and the ability to give the distance between two users would be a nice touch.

Thanks for your help,

sashak

    • [deleted]

    The postal codes differ from country to country, it might help if you say where you want to do the calculations for.

      Canada and the United States of course...

        Any country/continent actually. I'm just interested to know if such modules exist.

          Hi Sashak,

          I've achieved this in the UK, but don't know if exactly the same process would apply in other countries, though assume there would be something very similar.

          Basically in the UK each postal code has a grid reference, and there are different resolutions of grid reference depending upon the level you need. You simply look up the grid reference of the postal code entered for both post codes and given two sets of (X,Y) co-ordinates you can use Pythagoras theory to calculate the distance between the two places.

          However, there the further away the locations you may need to consider the arc of the earth into the equation. Within the UK this is not really a problem at all because it's only a small island, but a huge continent such as America, or Canada, this may become a problem if the postal codes are on opposite sides of the continent.

          Of course, the biggest problem you are likely to have is obtaining a reference source of postal codes against grid references. Again, I can only speak for the UK, but the Royal Mail offer a database of post codes which can be licensed, and is updated every six months. This database provides a listing of every postal point in the UK which has associated with it a grid reference.

          I hope this is of some use !

            Write a Reply...