﻿ Python GeoPy Package (Nominatim API): Get the city, state and country name of a specified latitude and longitude - w3resource # 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.

Sample Solution:

Python Code:

``````from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="geoapiExercises")
def city_state_country(coord):
location = geolocator.reverse(coord, exactly_one=True)
return city, state, country
print(city_state_country("47.470706, -99.704723"))
``````

Sample Output:

```('Bowdon', 'North Dakota', 'USA')
```

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Python: Tips of the Day

Function argument unpacking in Python:

Example:

```def tips_func(x, y, z):
print(x, y, z)

tuple_val = (2, 0, 2)
dict_val = {'x': 3, 'y': 2, 'z': 1}
tips_func(*tuple_val)
tips_func(**dict_val)
```

Output:

```2 0 2
3 2 1
```