Python 3 Geocoding Script to Convert Location to Latitude & Longitude Using geopy Library
543 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 friends welcome to this video
0:02
So in this video I will show you a
0:04
Python module which allows you to
0:08
extract the latitude and longitude from
0:10
a given address from a given location So
0:13
this is actually a module that is
0:16
specifically used if you go to the
0:19
Python package manager website just
0:22
search for this package which is
0:25
gi py This is a very famous package
0:29
which provides you with lots of methods
0:31
related
0:33
to Google maps So first of all you need
0:36
to install this and now I'll be showing
0:40
you how to get the latitude and
0:41
longitude from a given address the
0:43
geocoding So I basically provided this
0:46
location New Delhi You will
0:48
see and if I run this script
0:54
here you will see it will return the
0:57
coordinates which is your latitude this
1:00
is your latitude this is your longitude
1:02
So latitude and longitude are very much
1:05
important because they used to plot the
1:09
actual address on a Google map So if you
1:12
see a map this is a special coordinates
1:16
that you see you can see this is your
1:18
latitude and longitude It also gives you
1:21
the full address that the user has typed
1:23
here You can see
1:25
that and similarly here you can put any
1:28
location If I put
1:30
here
1:34
Sydney which is a city in Australia So
1:37
again run the script It will give you
1:39
the actual coordinates This is your
1:42
latitude This is your longitude And then
1:44
it gives you the entire
1:47
address You can also cross check If I
1:50
put
1:59
here so you can see that this is the
2:03
latitude this is the longitude
2:06
That's exactly it is returning So now I
2:09
will show you uh how to get started here
2:12
It's very
2:18
simple So first of all you need to
2:20
require this module So for requiring it
2:23
it's very easy
2:26
You simply create a python file and then
2:28
you require this module gopy and then it
2:33
contains this geocoders class From this
2:36
we need to import
2:38
this nominate So you first of all write
2:42
this line You require the necessary
2:44
modules After that we simply initialize
2:47
this geoloccator So we initialize a
2:50
variable and
2:52
then here we need to specify the user
2:56
agent and this needs to be you can give
2:59
the name to your user
3:01
agent something like this So this name
3:04
can be anything After you initialize
3:06
your user agents now you can
3:09
actually call this method which is
3:12
geoloc geoloccator dot and it contains
3:16
this function here which is geo code It
3:19
will uh tell you the latitude and
3:22
longitude Here you need to specify the
3:23
address physical address So right here
3:26
we specifically write here
3:34
Oakland and then we can print out all
3:36
these properties here such as the full
3:39
address location dot address then we can
3:42
print out the latitude and longitude You
3:44
simply say location dot latitude and
3:48
location
3:50
dot longitude So that's all that we need
3:54
to do You simply require the necessary
3:56
module Then we initialize the user agent
3:58
Then we use this method which is geo
4:00
code You provide the location which is
4:02
the city name And then it provides the
4:04
full address and the location latitude
4:07
and longitude If I try to execute this
4:09
you will see that now it will tell you
4:12
the exact address You'll see this is the
4:15
latitude This is the longitude So you'll
4:18
see So inside Python it's very much easy
4:21
You first of all require basically
4:24
install this package It's completely
4:27
free and uh it does the geocoding pretty
4:31
easily You provide the location then it
4:33
actually tells you the latitude and
4:35
longitude So you can put
4:40
any again just run
4:44
this So this is the latitude this is the
4:47
longitude this is the full address So
4:49
thank you very much guys for watching
4:51
this video and please hit that like
4:53
button subscribe the channel as well and
4:55
also check out my website
4:58
freemediattools.com
5:00
uh which contains thousands of tools