How to Find the Distance Between Two Places in Python

In this article, we show how to find the distance between two places in Python.
Specifically, we refer to latitudes and longitudes of places and how to find the difference between 2 places based on their latitude and longitude values.
So in order to calculate the distance between 2 places, we need the latitude and longitude of each place.
One such Python module that you can use to compute distance between 2 places is the geopy module.
The full documentation of this module can be found here: https://geopy.readthedocs.io/en/stable/
This module computes the distance between two points and can calculate the distance in miles, kilometers, meters, and so on.
To install this module, we use the following line.
So our program would go something as the following shown below.
So in this code, what you need to do is substitute values for the latitude and longitude values for each place.
So, for example, for place1, you can give the values of (42,-76).
For place2, you can give the values of (41, -75).
Of course, you can play with the values to see how the end calculation changes.
We choose to calculate the distance in miles. However, you can change this to kilometers, if you want to calculate the distance in kilometers, for example.
So the program will change to be that of the following below.
So this is a very good way of calculating the distance that exists between two points when the latitude and longitude values are known.
If you download this module in your Django project, you can use this to calculate distances between locations in the Django website.
Note that the distance calculated is the straight geographic distance between the 2 distances and not the travel or driving distance between the 2 points, which would be much more complex.
Related Resources
How to Randomly Select From or Shuffle a List in Python