Because of the near-spherical shape of the Earth (technically an oblate spheroid) , calculating an accurate distance between two points requires the use of spherical geometry and trigonometric math functions. However, you can calculate an approximate distance using much simpler math functions. For many applications the approximate distance calculation provides sufficient accuracy with much less complexity.
The following approximate distance calculations are relatively simple, but can produce distance errors of 10 percent of more. These approximate calculations are performed using latitude and longitude values in degrees. The first approximation requires only simple math functions:
Approximate distance in miles: sqrt(x * x + y * y) where x = 69.1 * (lat2 - lat1) and y = 53.0 * (lon2 - lon1)
You can improve the accuracy of this approximate distance calculation by adding the cosine math function
Improved approximate distance in miles: sqrt(x * x + y * y) where x = 69.1 * (lat2 - lat1) and y = 69.1 * (lon2 - lon1) * cos(lat1/57.3)
If you need greater accuracy, you can use the Great Circle Distance Formula. This formula requires use of spherical geometry and a high level of floating point mathematical accuracy - about 15 digits of accuracy (sometimes called "double-precision"). In order to use this formula properly make sure your software application or programming language is capable of double-precision floating point calculations. In addition, the trig math functions used in this formula require conversion of the latitude and longitude values from decimal degrees to radians. To convert latitude or longitude from decimal degrees to radians, divide the latitude and longitude values in this database by 180/pi, or approximately 57.29577951. The radius of the Earth is assumed to be 6,378.8 kilometers, or 3,963.0 miles.
If you convert all latitude and longitude values in the database to radians before the calculation, use