PDA

Click to See Complete Forum and Search --> : Getting people located new a zip code...


dclamp
Jun 18th, 2007, 02:49 AM
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

McCain
Jun 18th, 2007, 03:11 AM
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.

dclamp
Jun 18th, 2007, 01:55 PM
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.

visualAd
Jun 18th, 2007, 02:25 PM
Use the Google maps API ;)

PlaGuE
Jun 18th, 2007, 08:36 PM
Google Maps API, is good.

dclamp
Jun 18th, 2007, 09:24 PM
i dont want to have to use 3rd party code though...

dclamp
Jun 18th, 2007, 10:48 PM
i think this is the code that gives the zip codes... not sure though. looks complicated


$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 * (-1 * atan2($dist / sqrt(1 - $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...

NPassero
Jun 19th, 2007, 05:50 PM
i would get those into a database and test some out. some locations you know, to see if it actually works.