Python Geopy – Get latitude and longitude of an address

In this post we will be creating a Python script that will retrieve the latitude and longitude co-ordinates of a given 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 are wanting to retrieve the co-ordinates for the Bank of England in the United Kingdom. The prerequisite here is that we need to know the address of the Bank of England. This will then be converted in to latitude and longitude points.

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

Bank of England address – ‘Bank of England, Threadneedle St, London, EC2R 8AH’

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

from geopy.geocoders import Nominatim

Address='Bank of England, Threadneedle St, London, EC2R 8AH'

geolocator = Nominatim(user_agent="MyApp")

Bank = geolocator.geocode(Address)
print(str(Bank.latitude)+ ","+ str(Bank.longitude))

The above would return the following as output.

51.51413225,-0.08892476721255456
>>> 

We can then check these co-ordinates on Google maps to confirm this. See the image below as an example where can see the script was successful.

Bank of England latitude and longitude Coordinates

If your finding the location you’ve entered is not returning the correct co-ordinates, confirm it exists on the Nominatim street map by clicking here.

If your interested in getting the distance between two locations click here where we cover this in detail.

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