Finish project. Please read the readme.

Signed-off-by: Rick Hays <rhays@haysgang.com>
This commit is contained in:
2019-09-25 21:07:14 -05:00
parent 1c2488c808
commit ec443db999
8 changed files with 183 additions and 15 deletions

35
classes/geocode.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
class geocode
{
/**
* straight_line_distance - Returns Straight Line distance between two sets of (LAT/LONGS)
* @param real $lat1 - Latitude of Location #1
* @param real $lon1 - Longitude of Location #1
* @param real $lat2 - Latitude of Location #2
* @param real $lon2 - Longitude of Location #2
* @param string $unit - Unit of measure [DEFAULT = statute miles] ('K'=kilometers, 'N'=nautical miles)
* @return numeric - returns the distance in the desired unit of measure.
*/
public function straight_line_distance($lat1, $lon1, $lat2, $lon2, $unit='')
{
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K")
{
return ($miles * 1.609344);
}
else if ($unit == "N")
{
return ($miles * 0.8684);
}
else
{
return $miles;
}
}
}