Working with MongoDB and UK postcodes part 1: UK Post Codes

An important part of my next project involves letting people indicate whereabouts they are, but without disclosing detailed location information until later. In the UK, we have Post codes which are alphanumeric codes between five and eight characters long which broadly identify roughly where a building is. They are composed of two parts, the outward code and the inward code separated by a single space.Examples: IV51 9XB or SE22 8BS.

There are about 3000 outward codes, and while many cover a fairly small area especially in cities, others like IV51 cover several hundred square miles. Generally they are good enough for my purpose, and where the outward code isn’t specific enough I will use the first part of the inward code as well.

My plan is to use the postcode information here to identify the centre of each outward code and use that as a proxy for wherever the user is located. From that I can calculate a rough distance to other users. Where two users share an outward code, I can identify that fact and report it to the user doing the search.

Next time: Importing the data into MongoDB.