Results 1 to 8 of 8

Thread: Getting people located new a zip code...

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Getting people located new a zip code...

    I need to make a browse feature on my website where the user inputs a zip code (US), and selects a distance from that zip code (2 miles, 5 miles, 10 miles) and then it gets the users from the database who apply to that criteria.

    Where do i begin?? lol
    My usual boring signature: Something

  2. #2
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    Re: Getting people located new a zip code...

    Well, you're going to have to store the information in a database. Then you have to figure out how you want to store the distance information (i.e. should all users have a distance to all zip codes, or should they just have one distance to a common location, etc). Then you might have to do some calculations and then display the result.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting people located new a zip code...

    well the users all have their location stored in the database.

    I have this old script thats had zip code search, let me go take a look at it.
    My usual boring signature: Something

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Getting people located new a zip code...

    Use the Google maps API
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Getting people located new a zip code...

    Google Maps API, is good.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting people located new a zip code...

    i dont want to have to use 3rd party code though...
    My usual boring signature: Something

  7. #7

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Getting people located new a zip code...

    i think this is the code that gives the zip codes... not sure though. looks complicated

    PHP Code:
    $pi 3.14159265358979323846;
    $EARTH_RADIUS 3963.205# diameter/2 in miles

    $dist sprintf("%.1f"$dis);

    function 
    Distance($latitude1$longitude1$latitude2$longitude2)
    {
      global 
    $pi$EARTH_RADIUS;

      
    $dist 0;
      
    $latitude1 $latitude1 $pi 180#turn each from radians to degrees
      
    $longitude1 $longitude1 $pi 180;
      
    $latitude2 $latitude2 $pi 180;
      
    $longitude2 $longitude2 $pi 180;

      if((
    $latitude1 != $latitude2) || ($longitude1 != $longitude2)){
        
    $dist = (sin($latitude1) * sin($latitude2)) + (cos($latitude1) * cos($latitude2)) * cos($longitude2 $longitude1);
        
    $dist $EARTH_RADIUS * (-atan2($dist sqrt($dist $dist), 1) + $pi 2);
      }

      return 
    sprintf("%.1f"$dist);
    }

    //HERE IS WHERE THE FUNCTION IS CALLED

    if($first && $second)
    {
        
    $sql="select * from zips where zip like '$first'";
        
    $first_res=mysql_query($sql);
        
    $first_set=mysql_fetch_array($first_res);

        
    $flat $first_set["lat"];
        
    $flong $first_set["longitude"];


        
    $sql="select * from zips where zip like '$second'";
        
    $second_res=mysql_query($sql);
        
    $second_set=mysql_fetch_array($second_res);

        
    $slat $second_set["lat"];
        
    $slong $second_set["longitude"];
    }
    $miles Distance($flat$flong$slat$slong); 
    it looks like it gets them from a table `zips` and i am looking at the dump file, and there are 42k zip codes...
    Last edited by dclamp; Jun 18th, 2007 at 10:00 PM.
    My usual boring signature: Something

  8. #8
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: Getting people located new a zip code...

    i would get those into a database and test some out. some locations you know, to see if it actually works.

Posting Permissions

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



Click Here to Expand Forum to Full Width