Distance Equation Help, once again..
Posted: Mon May 01, 2006 4:25 am
Given a zip code 46952 with accurate lat and long
Trying to find a minimum/maximum lat & long within a 50 mile radius of that zip code:
I have this function:
Which outputs:
So, to sum it up: To find all locations within 50 miles of zip 46952, I would use those values in my query. However this pulls some (close but not accurate) data that is a bit off.
Is this function doing the math correctly?
Does anyone know of a good resource where I can find the min/max lats/longs within xx Miles of zip xxxxx to check my data against?
Code: Select all
Zip: 46952
Lat: 40.573173
Long: -85.668479I have this function:
Code: Select all
function getPoints($zip,$range){
// this pulls the data seen above
if(!$latlon = $this->getZipData($zip)){
return false;
}
// declare variables for easier usage
$lat = $latlon['lat'];
$lon = $latlon['long'];
// calculate ranges
$lat_range = $range/69.172;
$lon_range = abs($range/(cos($lat) * 69.172));
$min_lat = $lat - $lat_range;
$max_lat = $lat + $lat_range;
$min_lon = $lon - $lon_range;
$max_lon = $lon + $lon_range;
return array($min_lat,$max_lat,$min_lon,$max_lon);
}Code: Select all
Array
(
[0] => 39.8503371705 // min lat
[1] => 41.2960088295 // max lat
[2] => -86.4179771882 // min long
[3] => -84.9189808118 // max long
)Is this function doing the math correctly?
Does anyone know of a good resource where I can find the min/max lats/longs within xx Miles of zip xxxxx to check my data against?