|
-
Jun 18th, 2007, 01:49 AM
#1
Thread Starter
WiggleWiggle
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
-
Jun 18th, 2007, 02:11 AM
#2
Fanatic Member
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
-
Jun 18th, 2007, 12:55 PM
#3
Thread Starter
WiggleWiggle
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
-
Jun 18th, 2007, 01:25 PM
#4
Re: Getting people located new a zip code...
Use the Google maps API
-
Jun 18th, 2007, 07:36 PM
#5
Hyperactive Member
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.
-
Jun 18th, 2007, 08:24 PM
#6
Thread Starter
WiggleWiggle
Re: Getting people located new a zip code...
i dont want to have to use 3rd party code though...
My usual boring signature: Something
-
Jun 18th, 2007, 09:48 PM
#7
Thread Starter
WiggleWiggle
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 * (-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...
Last edited by dclamp; Jun 18th, 2007 at 10:00 PM.
My usual boring signature: Something
-
Jun 19th, 2007, 04:50 PM
#8
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|