A few months back I was working on a freelance project of visualizing geo-location data(i.e. latitude and longitude) in which I have to visualize central facilities and customers location on a map. As per one of the client’s requirements, I have to find all the customers locations that are within the range of 3 km from different facilities. To do this I have to calculate the distance between all the locations. It was the first time I was working with raw coordinates, so I tried a naive attempt to calculate distance using Euclidean distance, but sooner realized that this approach was wrong.

Euclidean Distance works for the flat surface like a Cartesian plain however, Earth is not flat. So we have to use a special type of formula known as Haversine Distance.

Haversine Distance__can be defined as__the angular distance between two locations on the Earth’s surface.

Haversine distance can be calculated as:

Looks Daunting, yes it would be daunting if you have to apply it using raw python code, but thanks to the python’s vibrant developers community that we have a dedicated library to calculate Haversine distance called haversine(one of the perks of using python).

That’s it with the introduction lets get started with its implementation:

#haversine #geolocation #haversinedistance #coordinates

Calculating Distance Between Two Geolocations in Python
2.55 GEEK