Coders Packet

Obtain the complete address using Geolocation in Python

By Pulkit Khandelwal

Hello everyone! In this tutorial, we are going to write Python code to get the complete address of a location just by entering the latitude and longitude of the required location.

Title of the project:

Obtain the complete address using Geolocation in Python

Project short description:

Hello everyone!

In this tutorial, we are going to write Python code to get the complete address of a location just by entering the latitude and longitude of the required location.

We are going to use the GeoPy library in Python.

Prerequisites:

  • Install Jupyter Notebook or any similar working environment with the latest version of Python installed.
  • You must know the Python language and its GeoPy library. 

Step by step implementation:

1) Install the GeoPy library on your computer just by running the following command in your terminal:
pip install geopy

2) Import the GeoPy library.
from geopy.geocoders import Nominatim

3) Initialize Nominatim API.
Geolocator = Nominatim(user_agent="geoapiExercises")

4) Enter the latitude and longitude of the required location.
latitude=input("Latitude: ")
print("Latitude=",latitude)
longitude= input("Longitude: ")
print("Longitude=",longitude)

5) Finally, get the complete address.
Location=Geolocator.geocode(latitude+','+longitude)
print('The address is',Location)

Complete Code:

from geopy.geocoders import Nominatim
Geolocator = Nominatim(user_agent="geoapiExercises")
latitude=input("Latitude: ")
print("Latitude=",latitude)
longitude= input("Longitude: ")
print("Longitude=",longitude)
Location=Geolocator.geocode(latitude+','+longitude)
print('The address is',Location)

Output:

Latitude= 28.61319453937331
Longitude= 77.22953115519925
The address is Pandara Park, Chanakya Puri Tehsil, New Delhi, Delhi, India

 

Download project

Reviews Report

Submitted by Pulkit Khandelwal (PulkitKhandelwal)

Download packets of source code on Coders Packet