Skip to main content
Вернуться к руководствам
3 min read6 Шаги

How to Calculate Great-Circle Distance using the Haversine Formula: Step-by-Step Guide

Calculate distance between GPS coordinates manually

Оставьте математику — воспользуйтесь калькулятором

Пошаговые инструкции

1

Convert Latitude and Longitude to Radians

First, identify the latitude and longitude of the two points in degrees. Then, convert these values to radians using the formula: radians = degrees * pi / 180

2

Calculate the Differences in Latitude and Longitude

Next, calculate the differences in latitude and longitude between the two points: Delta phi = phi2 - phi1, Delta lambda = lambda2 - lambda1

3

Apply the Haversine Formula

Now, plug in the values into the Haversine formula: d = 2 * arcsin(sqrt(sin^2(Delta phi / 2) + cos(phi1) * cos(phi2) * sin^2(Delta lambda / 2))) * R

4

Calculate the Distance in Kilometers and Miles

Finally, calculate the distance in kilometers and miles. The result from the Haversine formula will be in kilometers. To convert to miles, divide by 1.60934

5

Check for Common Mistakes

Double-check your calculations to avoid common mistakes, such as forgetting to convert latitude and longitude to radians or using the wrong radius for the Earth

6

Use a Calculator for Convenience

Consider using a calculator or an online tool for convenience, especially when dealing with multiple calculations or when precision is crucial

The Haversine formula is used to calculate the great-circle distance between two points on a sphere, such as the Earth, given their longitudes and latitudes. This guide will walk you through the steps to perform this calculation manually.

Introduction to the Haversine Formula

The Haversine formula is a formula used to calculate the distance between two points on a sphere. The formula is: [d = 2 imes \arcsin\left(\sqrt{\sin^2\left( rac{\phi_2 - \phi_1}{2} ight) + \cos(\phi_1) imes \cos(\phi_2) imes \sin^2\left( rac{\lambda_2 - \lambda_1}{2} ight)} ight) imes R] where:

  • (d) is the distance between the two points,
  • (\phi_1) and (\phi_2) are the latitudes of the two points in radians,
  • (\lambda_1) and (\lambda_2) are the longitudes of the two points in radians,
  • (R) is the radius of the sphere (approximately 6371 kilometers for the Earth).

Step-by-Step Calculation

To calculate the great-circle distance, follow these steps:

Step 1: Convert Latitude and Longitude to Radians

First, identify the latitude and longitude of the two points in degrees. Then, convert these values to radians using the formula: [radians = degrees imes rac{\pi}{180}]

Step 2: Calculate the Differences in Latitude and Longitude

Next, calculate the differences in latitude and longitude between the two points. [\Delta\phi = \phi_2 - \phi_1] [\Delta\lambda = \lambda_2 - \lambda_1]

Step 3: Apply the Haversine Formula

Now, plug in the values into the Haversine formula. [d = 2 imes \arcsin\left(\sqrt{\sin^2\left( rac{\Delta\phi}{2} ight) + \cos(\phi_1) imes \cos(\phi_2) imes \sin^2\left( rac{\Delta\lambda}{2} ight)} ight) imes R]

Step 4: Calculate the Distance in Kilometers and Miles

Finally, calculate the distance in kilometers and miles. The result from the Haversine formula will be in kilometers. To convert to miles, divide by 1.60934.

Worked Example

Let's calculate the distance between New York City (40.7128° N, 74.0060° W) and Los Angeles (34.0522° N, 118.2437° W).

First, convert the latitude and longitude to radians:

  • New York City: (\phi_1 = 40.7128 imes rac{\pi}{180} = 0.7106) radians, (\lambda_1 = -74.0060 imes rac{\pi}{180} = -1.2916) radians
  • Los Angeles: (\phi_2 = 34.0522 imes rac{\pi}{180} = 0.5934) radians, (\lambda_2 = -118.2437 imes rac{\pi}{180} = -2.0634) radians

Then, calculate the differences in latitude and longitude:

  • (\Delta\phi = 0.5934 - 0.7106 = -0.1172) radians
  • (\Delta\lambda = -2.0634 - (-1.2916) = -0.7718) radians

Now, apply the Haversine formula: [d = 2 imes \arcsin\left(\sqrt{\sin^2\left( rac{-0.1172}{2} ight) + \cos(0.7106) imes \cos(0.5934) imes \sin^2\left( rac{-0.7718}{2} ight)} ight) imes 6371] [d \approx 3935.75] kilometers

To convert to miles, divide by 1.60934: [d \approx 3935.75 \div 1.60934 \approx 2445.55] miles

Common Mistakes to Avoid

  • Forgetting to convert latitude and longitude to radians
  • Using the wrong radius for the Earth (use 6371 kilometers for the Earth)
  • Not using the correct formula for the Haversine formula

When to Use the Calculator for Convenience

While it's possible to calculate the great-circle distance manually, it's often more convenient to use a calculator or an online tool, especially when dealing with multiple calculations or when precision is crucial. The Haversine calculator can save you time and reduce the chance of errors in your calculations.

Готовы рассчитать?

Откажитесь от ручной работы и получите мгновенные результаты.

Открыть калькулятор

Сопутствующий смарт-контент

Настройки