Python GeoPy Package: Get the city, state and country name of a specified latitude and longitude
Default Options Object (Nominatim API): Exercise-6 with Solution
Write a Python function to get the city, state and country name of a specified latitude and longitude using Nominatim API and Geopy package.
from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent="geoapiExercises") def city_state_country(coord): location = geolocator.reverse(coord, exactly_one=True) address = location.raw['address'] city = address.get('city', '') state = address.get('state', '') country = address.get('country', '') return city, state, country print(city_state_country("47.470706, -99.704723"))
('Bowdon', 'North Dakota', 'USA')
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to find the location address of a specified latitude and longitude using Nominatim API and Geopy package.
Next: Write a Python program to calculate the distance between London and New York city.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join