# How to Calculate Distance between Two Points using GEOPY.

The geopy is a Python library which helps to calculate geographical distance. In this tutorial, we will discuss different methods of how the user can calculate the distance between two places on the earth.

First, the user has to install the geopy by using the following command:

After successful installation, we are ready to work with the geopy library.

## Calculate Distance between Two Points

Below are the important methods that used to calculate the distance between two points.

### Method 1: By using Geodesic Distance

The geodesic distance is the length of the shortest path between two points on any surface of Earth. In the following example, we will show how the user can calculate the Geodesic Distance from the latitude and longitude data.

Example:

Output:

```The distance between New York and Texas is:  2507.14797665193
```

### Method 2: By using Great Circle Distance

The great circle distance is the shortest path between two points on the sphere. In this case, we will assume the earth is the perfect sphere. The following example shows how the user can calculate great circle distance by using longitude and latitude data of two points.

Example:

Output:

```The distance between New York and Texas is:  2503.045970189156
```

### Method 3: By using Haversine Formula

The orthodromic distance is used for calculating the shortest distance between two latitudes and longitudes points on the earth's surface.

Using this method, the user needs to have the coordinates of two points (P and Q).

First, they have to convert the values of latitude and longitude points from decimal degrees to radians and then divide the values of latitude and longitude by (180/π). The user should use the value of "π = 22/7". Then, the value of (180/π) will be "57.29577". If the user wants to calculate the distance in miles, they can use the value of the radius of Earth, that is, "3,963". And if the user wants to calculate the distance in Kilo-metre, they can use the value "6,378.80".

Formulas:

The user needs the coordinates of P point and Q points in terms of longitude and latitude, then using the above formula for converting them into radians.

Now, calculate the distance between two points by using the following formula.

Formula:

For miles:

For kilometre:

Thus, the user can calculate the shortest distance between the two given points on Earth by using Haversine Formula.

Example:

Output:

```The distance between New York and Texas is:  2503.04243426357 K.M
The distance between New York and Texas is:  1556.985899699659 Miles
```

## Conclusion

In this tutorial, we have discussed various methods for calculating the distance between two points on the earth's surface by using the geopy library. We have shown examples of each method.

### Feedback   