Haversine Formula: Calculate Distance Between Two Points on Earth
This expression calculates the distance between two points on the surface of the Earth using the haversine formula.
'EARTHRADIUS' represents the radius of the Earth in the chosen unit of measurement (e.g., kilometers or miles).
'y1' and 'y2' represent the latitudes of the two points in radians.
'x1' and 'x2' represent the longitudes of the two points in radians.
The expression inside the Math.acos function calculates the central angle between the two points using the haversine formula.
The Math.sin(y1) * Math.sin(y2) term represents the sine of the difference in latitudes.
The Math.cos(y1) * Math.cos(y2) * Math.cos(x2 - x1) term represents the cosine of the central angle.
The Math.acos function returns the arccosine of the sum of these two terms, which represents the angular distance between the two points.
Multiplying this angular distance by the Earth's radius gives the linear distance between the two points on the Earth's surface.
原文地址: https://www.cveoy.top/t/topic/pcJp 著作权归作者所有。请勿转载和采集!