Friday, September 26, 2025
HomeLanguagesPython | Reverse Geocoding to get location on a map using geographic...

Python | Reverse Geocoding to get location on a map using geographic coordinates

Reverse geocoding is the process of finding a place or a location address from a given pair of geographic coordinates(latitude and longitude).
Modules needed: 
 

reverse_geocoder: A Python library for offline reverse geocoding.
pprint: A module which helps to "pretty-print" any arbitrary python data structure.

Installation: 
The modules can be easily installed using pip
 

pip install reverse_geocoder
pip install pprint

Examples: 
 

Input : (36.778259, -119.417931)
Output : 
Loading formatted geocoded file...
[{'admin1': 'California',
  'admin2': 'Fresno County',
  'cc': 'US',
  'lat': '36.72384',
  'lon': '-119.45818',
  'name': 'Minkler'}]
Input : (28.644800, 77.216721)
Output : 
Loading formatted geocoded file...
[{'admin1': 'NCT',
  'admin2': 'New Delhi',
  'cc': 'IN',
  'lat': '28.63576',
  'lon': '77.22445',
  'name': 'New Delhi'}]

Below is the implementation:
 

Python3




# Python3 program for reverse geocoding.
 
# importing necessary libraries
import reverse_geocoder as rg
import pprint
 
def reverseGeocode(coordinates):
    result = rg.search(coordinates)
     
    # result is a list containing ordered dictionary.
    pprint.pprint(result)
 
# Driver function
if __name__=="__main__":
     
    # Coordinates tuple.Can contain more than one pair.
    coordinates =(28.613939, 77.209023)
     
    reverseGeocode(coordinates)


Output: 
 

Loading formatted geocoded file...
[{'admin1': 'NCT',
  'admin2': 'New Delhi',
  'cc': 'IN',
  'lat': '28.63576',
  'lon': '77.22445',
  'name': 'New Delhi'}]

References: 
https://pypi.org/project/reverse_geocoder/ 
https://www.latlong.net/
 

RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6756 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS