1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Post/Zip Code Search

Discussion in 'Programming' started by hershel, Oct 5, 2005.

  1. #1
    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??
     
    hershel, Oct 5, 2005 IP
  2. gworld

    gworld Prominent Member

    Messages:
    11,324
    Likes Received:
    615
    Best Answers:
    0
    Trophy Points:
    310
    #2

    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.
     
    gworld, Oct 5, 2005 IP
  3. briandunning

    briandunning Active Member

    Messages:
    262
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    98
    #3
    There are *some* free resources on my page here (also some that are not free):

    zipwise.com/web-tools.php
     
    briandunning, Oct 5, 2005 IP
  4. Crazy_Rob

    Crazy_Rob I seen't it!

    Messages:
    13,157
    Likes Received:
    1,366
    Best Answers:
    0
    Trophy Points:
    360
    #4
    Crazy_Rob, Oct 5, 2005 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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 which should get you on your way... Here is such a UK database and this company sells both the database as well as a set of handy PHP functions which do it all for you.
     
    T0PS3O, Oct 5, 2005 IP
  6. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    dave487, Oct 6, 2005 IP
  7. hershel

    hershel Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Great guys - thanks for the tips, should be enough to get me started...
     
    hershel, Oct 6, 2005 IP
  8. dbtech

    dbtech Guest

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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
     
    dbtech, Oct 6, 2005 IP
  9. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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);
    
    PHP:
     
    dave487, Oct 7, 2005 IP