Python 3 Geocoding Script to Get Latitude and Longitude of an Address Using Geopy
607 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-geocoding-script-to-get-latitude-and-longitude-of-an-address-using-geopy/
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you a
0:04
Python module which will actually uh do
0:07
the geocoding process of converting your
0:10
address whatever address that you write
0:12
it will tell you the exact latitude and
0:15
longitude
0:17
uh coordinates so this Python script
0:20
will give you so for this we are using a
0:23
open-source package of
0:25
Python called as
0:29
Gopy and uh you can see this is actually
0:32
the Python geocoding package here simply
0:35
execute this command to install this
0:37
package i have already installed it so
0:40
now let me just show you a very simple
0:43
example so once I run this script
0:46
here I say python app py so it will tell
0:50
me to enter any address in the world so
0:53
it will convert this let's suppose I say
0:58
oakland so I basically written this com
1:01
address right here and now it will
1:03
convert this into latitude and longitude
1:05
so you'll see it will do the geocoding
1:07
process so it will give you these
1:09
coordinates so that you can plot this on
1:12
Google map exact latitude and longitude
1:15
so you can repeat this let's suppose I
1:18
say a different
1:21
address so this coordinate will be
1:24
different latitude and longitude so this
1:27
is a meant by geocoding which converts
1:29
your addresses into latitude and
1:31
longitude so now let me show you once
1:34
you install that package you simply say
1:38
from geopy
1:41
we have this geocoders and then from
1:43
this we import this
1:47
like this and then we
1:51
specify inside this main
1:57
function so here we uh ask the user to
2:01
enter the address so we use the input
2:04
function so here we simply ask the user
2:06
to enter the address then the user will
2:09
write the address and then we call this
2:11
custom function passing this address as
2:14
an argument so now we just need to
2:16
define this
2:22
function and this function will receive
2:25
the address as an argument so now we
2:29
will do the geo coding
2:31
process so this fun uh meth this module
2:36
here we'll call this and pass the user
2:39
agent and here you just need to give it
2:41
a name right here you can give any
2:44
name so after initializing this so this
2:48
contains a simple method which will
2:50
convert your address into latitude and
2:53
longitude so we simply say geo locator
2:58
and it contains this function geo code
3:01
and here you simply pass your address
3:04
and then you will it will return the
3:08
location if the location is there then
3:11
we simply print out the latitude and
3:16
longitude like this so location which
3:19
will be an object so it will contain
3:21
these properties location dot latitude
3:24
location longitude so it will print
3:27
out the actual coordinates so if the
3:31
address is not defined then in the else
3:33
block we will say
3:35
that the address can't be found you
3:38
can't find find coordinates for this
3:40
address so very simple script you ask
3:43
the user the address once again execute
3:46
this you ask you write the
3:53
address uh so the it gives you the
3:55
latitude and
4:08
longitude so so you can see that
4:11
so so this is meant by geolo coding here
4:15
to actually plot the latitude and
4:18
longitude using addresses so you can do
4:20
this unlimited number of times so there
4:22
is no restriction of putting any sort of
4:24
API key so thank you very much for
4:28
watching this video and also check out
4:30
my website freemediattools.com
4:33
uh which contains thousands of tools