Calculating the distance between two geocoordinate points with python.

Conrad Suuna
2 min readJun 19, 2020

--

Many mobile applications use this kind of technology for various reasons for example Tinder (for finding the distance between suiters). In my country, we have an Uber version called SafeBoda that uses the same technology to triangulate and pair different rider-passenger pairs for a means of quick transport and this is all achieved by knowing the distance between both parties.

Enough with the chit-chat. I got encountered with the task of developing an algorithm for doing the task at hand (calculating the distance between two geocoordinate points). The obvious steps to follow are;

  1. Generate the coordinates:- Here, you can use the Google Maps API to generate the respective coordinate points
  2. Calculate the distance (Reason for this writing).

Tool Used.

For this purpose, I used the Haversine distance formula and lucky enough, there’s a package in python that can help you avoid the headache.

Conclusion.

Much of Haverines’ simplicity comes from the underlying assumption that Earth is a perfect sphere (which it isn’t…). Because of this, it can lead to errors of up to 0.5%. More accurate methods exist but at the expense of computational complexity. [1]

There are other tools that can be used to calculate the distance. Read about them in the following;

  1. Lambert’s formula
  2. Great-circle distance
  3. Vicenty’s formulae

References.

[1] https://nathanrooy.github.io/posts/2016-09-07/haversine-with-python/

[2] https://janakiev.com/blog/gps-points-distance-python/

--

--

Conrad Suuna

Laravel dev, API dev, ML, AI and IBM Watson enthusiast.