Venta de libro - Fast Loans - Credit Cards UK - Chicago Website Design - Laptop PC

PDA

View Full Version : Post/Zip Code Search


hershel
Oct 5th 2005, 9:08 am
I want to add a service to my site where a visitor can enter their postcode (or zipcode) and a list of other members in their area are displayed - with those that share the same code appearing first and then those that are close by etc...

The first part can be done using a pretty straight forward search function (i'm sure!), its the second part where a list of those in neighbouring postcodes appear that i am having difficulties with - for example if i live in sw4 then how can i show all of those who live in in sw5, sw3 etc?

Does anyone have any idea how to go about this? or know of any resources that could point me in the right direction??

gworld
Oct 5th 2005, 9:32 am
I want to add a service to my site where a visitor can enter their postcode (or zipcode) and a list of other members in their area are displayed - with those that share the same code appearing first and then those that are close by etc...

The first part can be done using a pretty straight forward search function (i'm sure!), its the second part where a list of those in neighbouring postcodes appear that i am having difficulties with - for example if i live in sw4 then how can i show all of those who live in in sw5, sw3 etc?

Does anyone have any idea how to go about this? or know of any resources that could point me in the right direction??


You can not do that only with zip code, you need a zip code database that has latitude and longitute information of each zipcode; then you can find people with any radius from your own zip code.

briandunning
Oct 5th 2005, 11:03 am
There are *some* free resources on my page here (also some that are not free):

zipwise.com/web-tools.php

Crazy_Rob
Oct 5th 2005, 11:12 am
I've always used this one:

http://www.zipfind.net/products.aspx

T0PS3O
Oct 5th 2005, 2:15 pm
There's plenty of databases you can buy that have post code area centroids (lat/lon). Then with Pythagoras' theorem you can calculate distances.

Here's an intro (http://sniptools.com/latitudeLongitude.php) which should get you on your way... Here is such a UK database (http://www.evoxfacilities.co.uk/evox7.htm) and this company (http://www.graticule.com/index.html) sells both the database as well as a set of handy PHP functions which do it all for you.

dave487
Oct 6th 2005, 5:57 am
The way I have done this is as follows:

When a user signs up I use php to query www.postcodeanywhere.co.uk and they return an xml file showing the latitude and longitude of the users postcode. This is then saved to the database with the users details.

You can then enter any postcode and query www.postcodeanywhere.co.uk again to find out the latitude and longitudes and then use Pythagoras to compare them and work out the seperation distance.

Each query costs around 4 pence and I have the php scripts if you want.

see www.noblemarine.co.uk/repairers.php3 for an example.

hershel
Oct 6th 2005, 6:31 am
Great guys - thanks for the tips, should be enough to get me started...

dbtech
Oct 6th 2005, 10:02 pm
i don't think this should be easy unless you have a datbase or an algorithm that tells you the distance between to zip codes

dave487
Oct 7th 2005, 5:27 am
Once you know the coordinates of each postcode/zipcode the distance between them is very easy to calculate.

$dist1 = abs($easting1 - $easting2);
$dist2 = abs($northing1 - $northing2);
$dist1 = $dist1^2;
$dist2 = $dist2^2;
$distance_in_metres = $dist1 + $dist2;
$distance_in_metres = $distance_in_metres^0.5;
$distance_in_miles = $distance_in_metres/1609;
$distance_in_miles = number_format($distance_in_miles, 1);