Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function codexworldGetDistanceOpt($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo)
- {
- $rad = M_PI / 180;
- //Calculate distance from latitude and longitude
- $theta = $longitudeFrom - $longitudeTo;
- $dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);
- return acos($dist) / $rad * 60 * 1.852;
- }
- ///
- function circle_distance($lat1, $lon1, $lat2, $lon2) {
- $rad = M_PI / 180;
- return acos(sin($lat2*$rad) * sin($lat1*$rad) + cos($lat2*$rad) * cos($lat1*$rad) * cos($lon2*$rad - $lon1*$rad)) * 6371;// Kilometers
- }
- ///
- function getDistance($point1_lat, $point1_long, $point2_lat, $point2_long, $unit = 'km', $decimals = 2) {
- // Calculate the distance in degrees
- $degrees = rad2deg(acos((sin(deg2rad($point1_lat))*sin(deg2rad($point2_lat))) + (cos(deg2rad($point1_lat))*cos(deg2rad($point2_lat))*cos(deg2rad($point1_long-$point2_long)))));
- // Convert the distance in degrees to the chosen unit (kilometres, miles or nautical miles)
- switch($unit) {
- case 'km':
- $distance = $degrees * 111.13384; // 1 degree = 111.13384 km, based on the average diameter of the Earth (12,735 km)
- break;
- case 'mi':
- $distance = $degrees * 69.05482; // 1 degree = 69.05482 miles, based on the average diameter of the Earth (7,913.1 miles)
- break;
- case 'nmi':
- $distance = $degrees * 59.97662; // 1 degree = 59.97662 nautic miles, based on the average diameter of the Earth (6,876.3 nautical miles)
- }
- return round($distance, $decimals);
- }
- ////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement