Jump to content

Postcode problem


Love2c0de

Recommended Posts

Good evening,

 

I want to have a page where users can enter their postcode to find their nearest Citizens Advice Bureau. This is throughout England (excluding Ireland, Scotland and Wales).

 

My questions are:

 

How can I compare the post code entered by the user to the post code of the exisiting Citizens Advice Bureau's?

 

I know in PHP we can use a string function which compares the similarity between 2 strings but this clearly isn't going to suffice and work properly as you could have a CAB in London with post code SW1X 3RT (for example) and the users post code could be CM2 7ZN.

 

My initial thoughts are to store the addresses and post codes of all the CAB's in a table but how do I compare those values and be accurate?

 

The website company I work for have a similar functionality where we display certain things depending on user's post code so it is a fully post code driven site and I know our developer was coding a longitude and latitude script to determine this.

 

Is that the only way to be accurate or would there be an easier solution or even a better one?

 

Kind regards,

 

L2c.

 

 

Link to comment
Share on other sites

Sorry I'm finding this difficult to explain.

 

What I want is the user to enter their post code into an input, which will then display to them the nearest 5 citizens advice bureau addresses but ordered by distance from the users location.

 

Let's say I'm in London and for example lets say there are 10 citizens advice bureaus in that city. I want my page to return the 5 nearest CAB's relevant to the users post code. Even if one of those 5 CAB's is not WITHIN London, it should display the 5 nearest ones.

 

I need to determine what the distance is of each CAB depending on the users post code, then return to them 5 of the nearest CAB's

 

Kind regards,

 

L2c.

Link to comment
Share on other sites

Nearest - your best bet is to find an existing database that relates post codes to lattitude and longitude. I've done this with US zip codes, never tried UK. You can import that data into your program.

Another option is to use something like Google Maps API to calculate the routes. I've also done that and it works well.

Link to comment
Share on other sites

If you are just searching for a matching postcode then the problem is simple. I would strip out any spaces from the code before storing as you are never sure if the user will always put a space in the middle. The first part of the postcode can be 2,3 or 4 chars but the second part is always 3.

 

If you want to use distance to find the nearest then, as Jessica said, you will need the geographic locations of CABs and you will have to get a file of postcodes with their locations. You can use lat and long positions but, if you have them, Ordinance Survey eastings and northings are easier (you can just apply Pythagoras) as the coordinates are in metres.

Link to comment
Share on other sites

If you are just searching for a matching postcode then the problem is simple. I would strip out any spaces from the code before storing as you are never sure if the user will always put a space in the middle. The first part of the postcode can be 2,3 or 4 chars but the second part is always 3.

 

 

Good evening Barand,

 

I'm not searching for a matching postcode as such, I need to return some results based on the distance, ordered nearest to farthest.

 

 

If you want to use distance to find the nearest then, as Jessica said, you will need the geographic locations of CABs and you will have to get a file of postcodes with their locations. You can use lat and long positions but, if you have them, Ordinance Survey eastings and northings are easier (you can just apply Pythagoras) as the coordinates are in metres.

 

So I need to have some sort of file/database which is holding the addresses and post codes of all the CAB's nationally. I'm not quote sure about the last sentence and will be researching all of this shortly but is there a way to integrate a database of addresses and postcodes of CAB's into something like the Google Maps API?

 

Thanks for your input,

 

Kind regards,

 

L2c.

Link to comment
Share on other sites

What is the best format when storing addresses into a table?

 

Should I split the address into separate columns like:

 

house_name_or_number

street_name

city_or_town
county

post_code

 

Or should I just store it into one field as a full string?

 

Kind regards,

 

L2c.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.