Jump to content

Within X miles of zipcode logic?


cooldude832

Recommended Posts

How would zip codes tell distances anyways? There are only a handful of zip codes that exist anyways. Not every number can be a zip code.

 

Say my zip code is 32154 and I want 1 mile away from both sides. So you're saying 32155 and 32153 are zip codes too?

Link to comment
Share on other sites

How would zip codes tell distances anyways? There are only a handful of zip codes that exist anyways. Not every number can be a zip code.

 

There isn't a "handful" of zip codes, its a number defining a region in the Untied states by the Us Postal service.

Everyone knows the zipcode of their location.

 

I think this is beyond your scope, I found a db dump on it, but I think there is a simplier way

Link to comment
Share on other sites

well your unusualy what i came up with works

<?php
if(!empty($_GET)){
connectSQL();
$miles = intval($_GET['miles']);
$zip = intval($_GET['zip']);
if(strlen($zip) != 5){
	echo "Invalid Zip";
}
if(!empty($miles) && strlen($zip) == 5){
	connectSQL();
	$distance = $miles*(1/69);
	$q = "Select lng, lat from `zips` Where zip = '".$zip."'";
	$r = mysql_query($q) or die(Mysql_error()."<br /><br />".$q);
	if(mysql_num_rows($r) >0){
		$row = mysql_fetch_assoc($r);
		$min['lat'] = round($row['lat']-$distance,5);
		$min['lng'] = round($row['lng']-$distance,5);
		$max['lat'] = round($row['lat']+$distance,5);
		$max['lng'] = round($row['lng']+$distance,5);
		$where = "lat >= '".$min['lat']."' and lat <= '".$max['lat']."' and lng >='".$min['lng']."' and lng <='".$max['lng']."'";

		$q = "Select zip from `zips` Where ".$where;
		$r = mysql_query($q) or die(mysql_error()."<br /><br />".$q);
		if(mysql_num_rows($r) >0){
			while($row = mysql_fetch_assoc($r)){
				$zips[] = $row['zip'];
			}
		}
		else{
			echo "No Records found.<br />".$q;
		}
	}
	else{
		echo "Invalid Zip.";
	}
}
else{
	echo "Not valid search parameters.";
}
}
?>

Link to comment
Share on other sites

Hey look at that, Lat and Long...

 

yeah but thats like asking a person what their weight is in Newtons, they don't know, but they probably know their weight is in pounds so you convert it.  I thought there was a very generic zip -> location (lat,long) system based on the numbers, but I guess not.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.