SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    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)

    Trig experts...help me with some lat/long stuff

    Hey all

    I've gathered some code from several sources that allows me to do a zip-code radius lookup with a given radius and zip. For the most part, it works really well, but everyone so often, some test data I put in causes the lon range to be much to big. Here are the calculation for establishing a +/- value from a given radius (in other words, I'm really creating a box, not a circle)
    PHP Code:
    $lat_range round($radius/69.1726);
    $lon_range round(abs($radius/(cos($lat) * 69.172)), 6); 
    The $lat_range calculation is pretty straightfoward. I'm assuming the 69.172 is a rough constant for the number of miles per 1 latitude degree. It always seems to be accurate.

    The $lon_range, however, somtimes get's messed up. I'm struggling to see what the original author was doing here...

    Anyhow, any input is great. I'm gonna keep looking around, but most of my Google searches find me Zip Locator pages themselves, and not any code or methods behind the process.

    Oh, ya, here's my test page and click this link for an example when the lon_range is way off.
    Last edited by beetle; Oct 31, 2002 at 09:16.
    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




  2. #2
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,307
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i posted a function called haversine here:
    http://www.sitepointforums.com/showt...458#post531535
    not sure if that's going to be any use to you, but it might
    Last edited by johnyboy; Oct 31, 2002 at 15:39.

  3. #3
    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)
    1) I'm already using haversine for distance
    2) I've already fixed the problem anyway

    Thanks just the same
    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




  4. #4
    jigga jigga what? slider's Avatar
    Join Date
    Oct 2002
    Location
    Utah (USA)
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by beetle
    2) I've already fixed the problem anyway
    Well, how'd you fix it? What was wrong?
    $slider = 'n00b';

  5. #5
    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)
    Instead of finding a +/- range for the coordinates, I stuffed the calculations right into the SQL statment....

    Code:
    $sql = "SELECT $this->zipCol 
                    FROM $this->zipTable 
                    WHERE (    
                        POW((69.172*($this->lonCol-\"$this->lon\")*cos($this->lat/57.3)),2) +
                        POW((69.172*($this->latCol-\"$this->lat\")),2)
                        ) < ($this->radius*$this->radius) ";
    I got these calculations from another website...works great!
    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





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
  •