Python 3 geopy Reverse Geocoding Script to Get the City, State Info from Latitude and Longitude
875 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-geopy-script-to-get-the-city-state-and-country-info-from-latitude-and-longitude-in-cmd/
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 script which will actually return
0:06
the uh location the city state and
0:10
country information from the latitude
0:12
and longitude So it's a geocoding script
0:16
which where you will provide the
0:17
latitude and longitude which are the map
0:20
coordinates and through these
0:22
coordinates it will locate your identity
0:24
such as the city state country country
0:27
code and postal code it will return all
0:29
this information So let me just run this
0:31
script
0:32
here So we provided a bunch of latitude
0:35
longitude See it will return the city
0:38
here the state country and the zip code
0:41
as well And depending upon you can
0:44
actually search here So latitude and
0:49
longitude for
1:01
So similarly you can plug the latitude
1:05
longitude right here and it will give
1:07
you
1:08
different locations
1:15
So so this is a script here and it is
1:19
using a very popular package inside
1:21
Python If you just search here and just
1:24
say gopy this is essentially the python
1:27
geocoding library that we are using So
1:30
simply execute this command by
1:32
installing this I've already installed
1:35
it So let me just show you how to use
1:37
this So here you specify your geo pi
1:42
geocoders and from this you need to
1:44
import this
1:49
class from gopy
2:00
dot and then here you specify this
2:04
initialize this class and here you
2:06
specify your user agent
2:08
And here you can call this anything Let
2:10
me call this my G coder And then here
2:14
you specify a bunch of latitude
2:17
longitude So here you will replace your
2:19
own latitude longitude which you want to
2:22
locate And then for location locating we
2:26
just need to use this geoloccator dot
2:28
reverse geocoding So we are using this
2:32
reverse geocoding where we are providing
2:34
this latitude and longitude and based
2:37
upon that we are finding out the
2:42
address So now for finding out the
2:45
address we simply say location dot
2:50
raw we only need to get the
2:54
address And now for getting the city
2:56
information we say address
2:59
dot
3:01
get
3:05
city So similarly we can get more
3:07
information such as state country code
3:10
postal code from this address You will
3:13
see that
3:16
So so we can
3:19
print all this information using the
3:22
bunch of print statements So we are
3:24
printing out city state country and zip
3:27
code But if any sort of exception take
3:30
place we
3:32
can just show the exception So that's
3:36
all the script is this You can
3:39
see we are actually calling this is the
3:42
main function which is we are doing the
3:43
reverse geocoding We are finding the
3:46
latitude we are finding the address from
3:48
this latitude and longitude coordinates
3:51
So if I again see
3:54
this we'll
3:57
see
4:00
So you can just say delete
4:08
net So these are the every location has
4:12
this bunch of latitude longitude
4:14
coordinates So every map location has
4:19
this latitude and longitude So you can
4:22
search here on Google for a particular
4:26
location and then paste it and again run
4:29
this reverse geocoding script It will
4:31
give you the location here You will see
4:33
that city state country zip code So this
4:37
is a very simple reverse geocoding
4:39
script where we find out the
4:41
location from the latitude longitudes
4:44
reverse geocoding Uh thank you very much
4:46
for watching this video and please hit
4:49
that like button subscribe the channel
4:51
and also check out my
4:53
website uh freemediatools.com
4:56
uh which contains thousands of tools
#Geographic Reference