function earth_distance in Location 7.3
Same name and namespace in other branches
- 5.3 earth.inc \earth_distance()
- 5 earth.inc \earth_distance()
- 6.3 earth.inc \earth_distance()
- 7.5 earth.inc \earth_distance()
- 7.4 earth.inc \earth_distance()
Earth distance.
1 call to earth_distance()
- location_distance_between in ./
location.inc - Given two points in lat/lon form, returns the distance between them.
File
- ./
earth.inc, line 112 - Trigonometry for calculating geographical distances. All function arguments and return values measure distances in metres and angles in degrees. The ellipsoid model is from the WGS-84 datum. Ka-Ping Yee, 2003-08-11
Code
function earth_distance($longitude1, $latitude1, $longitude2, $latitude2) {
// Estimate the earth-surface distance between two locations.
$long1 = deg2rad($longitude1);
$lat1 = deg2rad($latitude1);
$long2 = deg2rad($longitude2);
$lat2 = deg2rad($latitude2);
$radius = earth_radius(($latitude1 + $latitude2) / 2);
$cosangle = cos($lat1) * cos($lat2) * (cos($long1) * cos($long2) + sin($long1) * sin($long2)) + sin($lat1) * sin($lat2);
return acos($cosangle) * $radius;
}