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:
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
Output:
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)
Latitude= 28.61319453937331
Longitude= 77.22953115519925
The address is Pandara Park, Chanakya Puri Tehsil, New Delhi, Delhi, India
Submitted by Pulkit Khandelwal (PulkitKhandelwal)
Download packets of source code on Coders Packet
Comments