Python 3 geopy Script to Calculate Distance Between Two Locations & Cities in Kilometres
2K views
Jun 3, 2025
Get the full source code of application here: Watch My Visual Studio Code IDE Setup Video For Fonts,Themes & Extensions https://youtu.be/Bon8Pm1gbX8 Hi Join the official discord server to resolve doubts here: https://discord.gg/cRnjhk6nzW Visit my Online Free Media Tool Website https://freemediatools.com/ Buy Premium Scripts and Apps Here: https://procodestore.com/
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you how to
0:04
calculate the distance between two
0:07
locations inside Python with a free
0:10
module called as gopy
0:13
uh which contains a method to calculate
0:15
the distance between two locations so
0:17
first of all you need to install this
0:18
module so pip install gopy i've already
0:22
installed this module so now after
0:25
installing it we written this simple
0:27
script we provide the location one
0:29
latitude and longitude and location two
0:32
latitude and longitude and then we
0:34
calculate the distance between these two
0:36
locations so if I try to run this Python
0:39
script you will see it will provide you
0:41
with a distance which is in kilometer
0:46
58553.10
0:48
kilometer so this is your stat statue of
0:52
liberty and this is your eel tower
0:59
so so I will show you how to initialize
1:02
this so first of all using this module
1:05
free module it contains this distance
1:08
class we need to import this and here we
1:13
need to specify the location one
1:15
latitude and longitude so latitude and
1:18
longitude are nothing but the locations
1:21
or coordinates that you specify while
1:23
plotting locations on a Google map so
1:26
these are used in plotting on a physical
1:29
map so here we are providing these
1:31
latitude and longitudes and then after
1:33
that we need to calculate the distance
1:35
between them so this provides you with a
1:38
simple
1:40
method so here we specify these two
1:43
locations location one comma location
1:45
two and then it has this
1:49
uh kilometers property so it will
1:52
provide you with the distance how much
1:54
distance is there so here you can simply
1:57
print out the distance like
2:01
this
2:06
so it's a very handy module guys you can
2:09
see distance between two locations is
2:11
that
2:14
so we can even convert this let's
2:17
suppose you only want to write the two
2:20
locations you can use chat GPT here so I
2:23
will say just convert the
2:28
script so that I don't want to
2:33
provide latitude and longitude
2:37
we just want to write city names so I'm
2:42
just asking chart GPT so that we can
2:44
instead we can write city names instead
2:46
of writing the latitude and longitude so
2:49
it has given me this script here if I
2:52
paste the script so instead providing
2:55
the latitude and longitude now we
2:57
providing two city names you can see
2:59
this is the city one this is city 2 and
3:03
then it does the same thing if I run
3:06
this script now you will
3:12
see you first of all need to initialize
3:25
this so you will see distance between
3:27
New York New York City and Paris is
3:30
58560 kilometer so in this easy
3:34
way now instead of providing latitude
3:37
and longitude we provided two cities
3:40
city one city 2 and then first of all we
3:43
convert this into the latitude and
3:47
longitude for this we use geocoding
3:50
method for this this module is a very
3:53
handy module it provides you with this
3:56
method which is geocode so we convert
3:59
these physical locations into latitude
4:01
and longitude by using this method after
4:04
we get this latitude and longitude we
4:06
store it inside these two variables and
4:08
then we actually provide the kilometers
4:12
we again use the same method geo
4:16
description we provide these two
4:18
locations and then we simply print the
4:21
location uh distance between two these
4:24
two
4:25
cities and you can cross verify as well
4:28
so if I say distance
4:32
between New York City and
4:40
Paris so it's
4:44
3625 I will say in
4:48
kilometer 58 33 kilometer so again this
4:52
script is also returning the same result
4:55
it's round about the same here which is
4:59
5850 google is telling me it is 5833
5:02
it's round about the same so we can
5:04
change the locations here let's suppose
5:06
I say I want to dis Sydney to
5:11
Oakuckland so I've given the script guys
5:14
in the description of the video if you
5:15
need the script you can go to my website
5:18
and copy paste the script it's very
5:20
simple the nice part is that it's
5:22
completely free you don't need any sort
5:25
of API key you simply uh replace the
5:28
locations and then it will tell you the
5:29
distance between the two locations so
5:31
you can see that so thank you very much
5:34
guys for watching this video and also
5:37
check out my website freemediattools.com
5:40
uh which contains thousands of tools