SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ZIP proximity based search. How to?

    I came across this on www.autotrader.com, a search based on proximity to a zip code. Any clues on how that could be done? I figured out a way for localized search based on IP but this just bowled me over.

  2. #2
    SitePoint Member
    Join Date
    May 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would imagen its based on a calulation from both latitude and longitude values of both places

  3. #3
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Russeh
    I would imagen its based on a calulation from both latitude and longitude values of both places
    I thought about this but what I need to know is how to go about searches like "within 50 Km's of 90210"

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigduke
    I thought about this but what I need to know is how to go about searches like "within 50 Km's of 90210"
    IIRC, you can download census data which give longitude and latitude for every postal code.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would imagen its based on a calulation from both latitude and longitude values of both places
    Not so long ago, just the other week in fact, there was a thread in the database/MySql forum about this yes?

    There was a solution found if I remember, based on the actual calculation which may shed some light on it for you, if you care to go over the last couple of weeks threads, that is

  6. #6
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Not so long ago, just the other week in fact, there was a thread in the database/MySql forum about this yes?

    There was a solution found if I remember, based on the actual calculation which may shed some light on it for you, if you care to go over the last couple of weeks threads, that is
    http://www.sitepoint.com/forums/showthread.php?t=211046

    Maybe?

  7. #7
    SitePoint Addict fesh's Avatar
    Join Date
    Jan 2005
    Location
    Jackson, New Jersey
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just started work on a zip code search. The formula used most often (due to computing power restraints) is

    sqrt(x^2 + y^2)

    where:

    x = 69.1 * (lat2 - lat1)
    y = 69.1 * (long2 - long1) * cos(lat1/57.3)

    the way I do it is have a database with all the zip codes in it. Then I have the user input a zip. It finds the latitude and longitude of their zip then compares it through the above equation. This finds an approximation, not exact because of the computing restraints.
    Fesh
    imagine what it's going to be like

  8. #8
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks fesh and Dylan thats what I was looking for

  9. #9
    SitePoint Addict fesh's Avatar
    Join Date
    Jan 2005
    Location
    Jackson, New Jersey
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    always glad to be of help.
    Fesh
    imagine what it's going to be like

  10. #10
    SitePoint Enthusiast DmS's Avatar
    Join Date
    Jan 2004
    Location
    Stockholm, Sweden
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also take a look here http://www.ozoneasylum.com/21781 , I did this sort of zip-distance search just like this a while back and collected a lot of good info plus some example code under that link. Including links to zip-code data (if they still work that is )
    /Dan
    { knowledge is what remains once you forget what you learned }
    Home: DmSProject Tutorials: GurusNetwork
    Committed at:
    OzoneAsylum + Blog

  11. #11
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe?
    Spot on

    Has anyone considered using or has used, a Web Service yet? Does anyone know of such a service exists?

    Thanks

  12. #12
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by Dr Livingston
    Does anyone know of such a service exists?
    Gives me an idea, how about implementing a web service for it ?

  13. #13
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigduke
    I came across this on www.autotrader.com, a search based on proximity to a zip code. Any clues on how that could be done? I figured out a way for localized search based on IP but this just bowled me over.
    If you are looking for a solution specific for the US, you may want to take a look at these two classes: php Zip Locator and Zip Codes Range .

    They both search a database of US zip codes and geographic coordinates to compute the distance. The first is more accurate but leads to table full scan on every search. The second is not very accurate, but for the purpose of excluding zip codes that are too far away it is much faster as it exclude entries that are too far in latitude and longitude, so with a range index on the coordinate fields it avoids table full scan and is obviously much faster despite it may end up including zip codes that are of your desired distance circle. A combination of both approaches would be ideal.

    These solutions could be generalized for other countries in the world if you are able to find a database with zip codes for the countries you are interested.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP

  14. #14
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone had any luck finding Australian post codes with long and lat?

  15. #15
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mlemos excellent resource there mate, i hogged on it immediately.

    Absolution, OZ land is still better organized and I'm sure there's one out there somewhere. Try asking the nearest post office for it.

    I wonder if there even IS a list of zip codes by long at lat for India

  16. #16
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigduke
    Thanks fesh and Dylan thats what I was looking for
    No problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •