Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macmuse

macrumors newbie
Original poster
Mar 29, 2007
2
0
I'm looking for a ZIP CODE RADIUS SEARCH (not a ZIP CODE DISTANCE CALCULATOR) for my Mac server FMPro database. What it would do: When a search is performed based on the mile radius from a stated zip code (say 200 miles from zip 37922, for example) it should pull up all the records containing zip codes within that mile radius or proximity of that zip code. I have been looking for this for a long time and need it very much. I have found all kinds of code and software that are PC compatible, but not for Mac. I have actually seen this exact ZIP CODE RADIUS (PROXIMITY) search field on the Apple web site in their search feature for user groups, but I can't find it available for Mac FileMakerPro database. Does anyone know of one. I need to incorporate this search into my web site search engine so visitors can perform this search. My site is hosted on a Mac server. Programs, software, pug-ins, script, etc. (whatever works) is fine. I'm not interested in subscription type services offering this. Any help would be greatly appreciated. Thanks macmuse:)
 
Clarification - Needed - a web ZIP CODE RADIUS SEARCH for FileMakerPro

Thanks for your reply, iSaint, but that is not what I am looking for. ALL - a clarification. I am NOT looking for something that calculates the distance between two Zip Codes (between two points). What I need is a ZIP CODE RADIUS SEARCH feature compatible with FileMakerPro database set up to run with a web site. What this does: The records entered into a FileMakerPro database (via a web form entry page) each include an address with a Zip Code. When setting up the search fields on a web site to search this database, the search feature would be for ALL records that have Zip Codes that fall within that mile radius. Example: If I am looking for all records with Zip Code locations within a 100 mile radius of where I live (my Zip Code), I would type in my Zip Code in one field and the mile radius (100 miles) in the second field and the search results would be ALL records with Zip Codes that fall within that 100 mile radius. This search feature needs to run on a web site hosted on a Mac SERVER. If anyone knows of a FileMakerPro plug-in, a program, macro, or Mac Compatible software, etc. that can achieve this, I would be very appreciative. I have found this capability designed for PC's, but not for Mac so far. I am NOT looking for any SUBSCRIPTION SERVICES that offer this. I want to put it on my own server/FileMakerPro to run. Any help please? Thanks macmuse
 
macmuse, give people a chance to read your thread before bumping it unecessarily or starting new threads.

If your original post isn't clear enough or doesn't say what you'd like it to say, just use that little blue "Edit" button and edit your post. Likewise, CAPS LOCK can be a bit off-putting as well as a really long paragraph...

Just relax, wait a little, I'm sure someone will be able to point you in the right direction. :)
 
This one seems pretty nice.

Sounds like you download the data and could then store in in a related FM database to use for lookups.
 
There is a free database of Zip codes, city names, and locations (lat/long and state) from David Weekly.. the site appears to be down. I have a copy if you want it.

I hacked up my own calculator in PHP. The code is below if you can adapt it to work.

PHP:
function getRangeBox($lat, $lon, $range) {

    // Calculate the degree range using the mile range
    $degrees = $range * .01445;

    // Get the coords for our starting zip code.
    //list($starting_lon, $starting_lat) = $this->getLonLat($this->zipCode);
    
    // Set up an array to return.
    $ret_array = array ();

    // Lat/Lon ranges 
    $ret_array['max_lat'] = $lat + $degrees;
    $ret_array['max_lon'] = $lon + $degrees;
    $ret_array['min_lat'] = $lat - $degrees;
    $ret_array['min_lon'] = $lon - $degrees;

    return $ret_array;
  }

function Calculate_distance($lat1, $lon1, $lat2, $lon2) {
//$theta = $lon1 - $lon2."<br>";
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);

return $miles = /*round(*/$dist * 60 * 1.1515/*, 2)*/;

}

/// zipRadius()  - find zip codes within radius of zip code
function zipRadius($center, $miles) {
	global $config;
	
	global $ctrstr;
	$ctrstr = mysql_query("SELECT cityname, state, longitude, latitude FROM zips WHERE zip = '$center'");
	if (mysql_num_rows($ctrstr)==0) return false;
	$box = getRangeBox(mysql_result($ctrstr,0,'latitude'),mysql_result($ctrstr,0,'longitude'),$miles);
	
	$search = mysql_query("SELECT zip, cityname, state, latitude, longitude FROM zips WHERE latitude >= ".$box['min_lat']." AND latitude <= ".$box['max_lat']." AND longitude >= ".$box['min_lon']." AND longitude <= ".$box['max_lon']);
	
	while ($row = mysql_fetch_array($search)) {
		$distance = Calculate_distance(mysql_result($ctrstr,0,'latitude'), mysql_result($ctrstr,0,'longitude'), $row['latitude'], $row['longitude']);
		
		if ($distance <= $miles) {
			$info[] = array(
		'distance' => $distance,
		'zip' => $row['zip'],
		'cityname' => $row['cityname'],
		'state' => $row['state']
		);
		}
	}
	
	array_multisort($info);
	
	return $info;
}
///
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.