SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    distance between zip codes

    Any ideas how I would try to measure the mileage between two zip codes (6 state area)? Anybody got any scripts for this or know wher3e to find one? Or do I need to get distances manually by doing Yahoo Map searches?

    Sketch
    Aaron Brazell
    Technosailor



  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sketch, if you do an advanced search, I know that someone actually posted either the code for this or the algorithm some time ago. Could be exactly what you are looking for.


  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there's no way to calculate the distance between ZIP codes that i know of Sketch. what freakysid is talking about is code to calculate the distance between 2 points of latitude and longitude. i just finished an application that does this. i do the calculation in my MySQL query. this is plenty accurate for distances less than, say, 500 miles. you can get more accurate using the sine and arc cosine functions. here's the formula (from my query):

    Code:
    SQRT(POW(lat1 - lat2, 2) + POW((lon1 - lon2) * COS(RADIANS((lat1 + lat2) / 2)), 2))
    then you can just multiply that value by the miles in a degree of latitude, which is about 70.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could just double your age and add the temperature and call it a calculated guess.

    Well. hehe, err, um, ...

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like that method best, freaky!

    Anybody got any recommendations on buying a db of zips with lat and long in the db? I surely don't want to have to create it....

    Sketch
    Aaron Brazell
    Technosailor



  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    speak to flawless_coder as he has something like that.

  7. #7
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql statement?

    I found a database of lat and long on a government database.

    DR_LaRRY_PEpPeR, how do you do your MySQL statement?

  8. #8
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Re: mysql statement?

    Originally posted by jkh1978
    I found a database of lat and long on a government database.
    i could use something like that. would you post the url please jkh? i'd appreciate it if you would

  9. #9
    SitePoint Evangelist -Oz-'s Avatar
    Join Date
    Nov 2001
    Location
    Phoenix, AZ, USA
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats pretty advanced, but make sure that the distance isn't too long, you should really use the curves to make the distance because you are going through earth currently with that algorithm. You have to make sure that you stay on the surface and that also depends what direction you are going. I don't know the algorithm i just know that it is neccessary for an accurate distance measurement.

    --a high school senior
    Oz
    GamersMark - On Target Gaming
    OzTheory - Programming and Web Solutions
    AmIBlocked - Check if you've been blocked on IM

  10. #10
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    North Carolina
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The telephone LD industry uses a database of this type of information for calculating rates of calls(internally). On a project I'm working with one of the item's we'll be having to purchase is this list of lats & lons for rerating LD bills.

    I don't remember who has the list exactly, but I'm thinking it's Bell something...

  11. #11
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is no such thing as a distance between zip codes. They are based on Population Density. For XXX Amount of population you get a new zip code. I believe it is 50,000 people. This doesn't account for Zip Codes assigned to pre-sorted mail and post office boxes either.

    For calculating mileage on a map and accounting for the curvature of the earth, Larry's calculation looks spot on. I did this almost two years ago in an Oracle application. I can't find the code right now however.

    If you go to the U.S. Census Bureau's website, you can order TIGER data that allows you plot every address in the United States. It isn't the best mapping data but costs a lot less than what you would get from MapInfo or Telcontar which would run you in the 10,000s of thousands of dollars.

    I have Telcontar's map data for California and Nevada here at home and that cost $1500.00. It is also 1999 data so it is probably out of date by now.
    Wayne Luke
    ------------


  12. #12
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by -Oz-
    thats pretty advanced, but make sure that the distance isn't too long, you should really use the curves to make the distance because you are going through earth currently with that algorithm. You have to make sure that you stay on the surface and that also depends what direction you are going. I don't know the algorithm i just know that it is neccessary for an accurate distance measurement.

    --a high school senior
    the curved way from here -
    http://www.phpbuilder.com/snippet/de...=snippet&id=61

    code from there -
    Code:
    # Where:
    #  $l1 ==> latitude1
    #  $o1 ==> longitude1
    #  $l2 ==> latitude2
    #  $o2 ==> longitude2
    
    function haversine ($l1, $o1, $l2, $o2)
    {
    	$l1 = deg2rad ($l1);
    	$sinl1 = sin ($l1);
    	$l2 = deg2rad ($l2);
    	$o1 = deg2rad ($o1);
    	$o2 = deg2rad ($o2);
    				
    	return (7926 - 26 * $sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin ($l2) * $sinl1) - cos ($l1) * cos ($l2) * cos ($o2 - $o1)))));
    }

  13. #13
    SitePoint Evangelist -Oz-'s Avatar
    Join Date
    Nov 2001
    Location
    Phoenix, AZ, USA
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    coolness
    Oz
    GamersMark - On Target Gaming
    OzTheory - Programming and Web Solutions
    AmIBlocked - Check if you've been blocked on IM

  14. #14
    SitePoint Enthusiast
    Join Date
    May 2002
    Location
    Pittsburgh PA
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe that there are centroid lat lon locations for zip codes. It would only be an approximation. You need to check on data from GIS (geographic information systems) suppliers, I think.

    Alex

  15. #15
    SitePoint Enthusiast adent100's Avatar
    Join Date
    Nov 2004
    Location
    Atlanta, Georgia
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GIS zip code data...

    For GIS zipcode data, I would recommend to places:

    1. www.nationalatlas.gov

    2. www.geographynetwork.com.

    At each place, you can download geographic data that may include centroids for zip code polygons. Incidentally, a zipcode is not really an "area" but a network of street segments. These segments are grouped together for the convenience of delivering the mail.

    May want to go to usps.gov (the US Post Office) also.

    Cheers!

    Andy

    P.S. You can download free GIS software (called ArcExplorer) from www.esri.com. This will help you handle spatial data that you download and convert it to other formats for use in your application.

  16. #16
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  17. #17
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Boston
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi


    I will share my code with you.... (offer only to the original poster)

    PM me if you want the best code possible! The method I use gives the best results, I designed it using earth models and NASA geo thermo plates! I will also give you any (1) database from any (1) country in the world. Each database has every city/place and postal code!

    Example....

    http://zip.ya-right.com/distance/us/zip.php


    C, ya...

    J!


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
  •