Search through postcode.

Discussion in 'PHP' started by Alan Murray, Nov 16, 2006.

  1. #1
    What would the best way for a search feature that locates the nearest store by the user entering there postcode? This is for the uk.
     
    Alan Murray, Nov 16, 2006 IP
  2. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've never done it with UK, but I've done it with US. In the US, there are zip code databases that give you longitude and latitude for the center of most (nearly all) US zip codes. From there you can calculate distance.

    I would assume the same holds true for UK. A quick search at google reveals a solution at HotScripts:

    http://www.hotscripts.com/PHP/Scripts_and_Programs/Zip_Code_Locators/index.html

    I skimmed the first 2 pages of results at Google and didn't find any detailed tutorials or additional information on it, but no doubt its out there if you're willing to sift through more pages of results.

    In the end, the real key is a database of zip code to latitude and longitude. From there, you could easily use a US distance script (some are freely available) calculator as a model to build one for UK.
     
    ajscottsr, Nov 16, 2006 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've created a few of these applications. You need to use postcodeanywhere.co.uk to buy postcode lookups (4p per lookup).

    Create a database in mysql of all your store locations (postcode, address, easting, northing) and then you can use a php script to lookup the coordinates of the client postcode with postcodeanywhere and compare it using a formula to the stores in the DB.

    Then output your data from the array and order it by distance.
     
    mad4, Nov 16, 2006 IP
  4. Lukas

    Lukas Well-Known Member

    Messages:
    1,299
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    130
    #4
    you know of 1 cheaper than ultmte lctr..?

    it has all the features I need but for $249 it's just too much.

    my database will have thousands of entries. I also need to be ale to add or delte additional search fields & chaneg the results template page.
     
    Lukas, Nov 16, 2006 IP
  5. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    A search on google for 'postcode to lat long' turns up quite a few resources which you should be able to integrate into your search script.
     
    streety, Nov 16, 2006 IP
  6. Alan Murray

    Alan Murray Well-Known Member

    Messages:
    1,044
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    145
    #6
    Thank you for the help.
     
    Alan Murray, Nov 17, 2006 IP