Calculating the distance between two places using geopy Python

In this tutorial, we are going to calculate the distance between two places using geopy in Python with some cool and easy examples. In many situations, you might have to come up with this type of requirement.

If you don’t know about this topic and its methods then you are at the right place looking for a solution. Because in this tutorial we gonna learn about this topic and its methods in Python.

distance between two places using geopy

In windows, to use geopy you need to install it by entering the command in command prompt.

pip install geopy

Whereas if you are using Pycharm then the installation process is entirely different.
Pycharm -> File -> Settings -> Python interpreter -> + -> geopy -> install package.

Let’s learn this with some cool and easy examples.
At first, we are going to find the distance between two points having coordinates.

from geopy.distance import geodesic 

x = (22,88) 
y = (28,77) 
  
print(geodesic(x,y).km)

Output:

1318

Now if the graph is a sphere and we are going to calculate the distance between two points having coordinates on a sphere.

from geopy.distance import great_circle 
  
x = (22, 88) 
y = (28, 77) 
  
print(great_circle(x, y).km)

Output:

1317

So in this way, we can calculate the distance between two points using geopy in python by installing geopy. We have seen here two methods. one is a simple method that is calculated on any surface and the other is the great circle method that is calculated on a sphere.

Leave a Reply

Your email address will not be published. Required fields are marked *