Python Geopy – Get address using latitude and longitude

In this post we will be creating a Python script that will convert a set of latitude and longitude co-ordinates into an address. To do this we will be using the Geopy library which is a Python client for several popular geocoding web services. To install the library run the following in command line.

pip install geopy

For this example we will be providing co-ordinates for the Bank of England in the United Kingdom. These can be seen below.

Note: For more on the Python Geopy library click here.

Bank of England co-ordinates – ‘51.51413225,-0.08892476721255456’

See the sample of Python code below which will convert our latitude and longitude co-ordinates and return the address to output.

from geopy.geocoders import Nominatim

geolocator = Nominatim(user_agent="myGeoAPI")

location = geolocator.reverse("51.51413225,-0.08892476721255456")

print("Address:", location.address)

The above would return the following as output.

Address: Bank of England, 8AH, Threadneedle Street, Cornhill, City of London, Greater London, England, EC2R 8AH, United Kingdom
>>> 

Take a look at some of our other content around the Python programming language here. Also find some more posts on the Geopy library by clicking here.

Leave a Reply