Sunday, December 7, 2025
HomeLanguagesPython | Calculate Distance between two places using Geopy

Python | Calculate Distance between two places using Geopy

GeoPy is a Python library that makes geographical calculations easier for the users. In this article, we will see how to calculate the distance between 2 points on the earth in two ways.

How to Install GeoPy ?

pip install geopy

 
Geodesic Distance:
It is the length of the shortest path between 2 points on any surface. In our case, the surface is the earth. Below program illustrates how to calculate geodesic distance from latitude-longitude data.




# Importing the geodesic module from the library
from geopy.distance import geodesic
  
# Loading the lat-long data for Kolkata & Delhi
kolkata = (22.5726, 88.3639)
delhi = (28.7041, 77.1025)
  
# Print the distance calculated in km
print(geodesic(kolkata, delhi).km)


Output:

1318.13891581683

 
Great Circle Distance:
It is the length of the shortest path between 2 points on a sphere. In this case, the earth is assumed to be a perfect sphere. Below program illustrates how to calculate great-circle distance from latitude-longitude data.




# Importing the great_circle module from the library
from geopy.distance import great_circle
  
# Loading the lat-long data for Kolkata & Delhi
kolkata = (22.5726, 88.3639)
delhi = (28.7041, 77.1025)
  
# Print the distance calculated in km
print(great_circle(kolkata, delhi).km)


Output:

1317.7554645657162

Reference: https://geopy.readthedocs.io/en/stable/

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32427 POSTS0 COMMENTS
Milvus
103 POSTS0 COMMENTS
Nango Kala
6803 POSTS0 COMMENTS
Nicole Veronica
11944 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12014 POSTS0 COMMENTS
Shaida Kate Naidoo
6934 POSTS0 COMMENTS
Ted Musemwa
7188 POSTS0 COMMENTS
Thapelo Manthata
6882 POSTS0 COMMENTS
Umr Jansen
6867 POSTS0 COMMENTS