Once the location is identified, GetCityName flow is used to get the name of the city from places list. First occurrence of the city is selected.
In case of no city identified, an exception is raised and is handled by defaulting the city to home city.
1
try:
2
city_name = places.cities[0]
3
return city_name
4
except Exception as e:
5
city_name = homeCityName
6
return city_name
Copied!
geograpy extracts place names from a URL or text, and adds context to those names -- for example distinguishing between a country, region or city.
The extraction is a two step process.
The first process is a Natural Language Processing task which analyzes a text for potential mentions of geographic locations.
In the next step the words which represent such locations are looked up using the Locator.
If you already know that your content has geographic information you might want to use the Locator interface directly.
Identify Latitude and Longitude
geoLocateLatitudeLongitude flow is executed to Identify the Latitude and Longitude, City Name is passed to geopy package to identify the Latitude and Longitude of the given City.
geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources.
Import Nominatim from geopy- Nominatim is a free service or tool or can be called as API with no keys that provides you with the data after providing it with name and address and vice versa.
On calling Nomination tool which accepts an argument of user_agent you can give any name as it considers it to be the name of the app to which it is providing its services. Here we are using user_agent Name as Aryan.
The geocode() function accepts the location name and returns a geodataframe that has all the details and since it’s a dataframe we can get the address, latitude and longitude by simply calling it as in snippet below.
Once Latitude and Longitude are Identified getTimeZoneValue flow is executed and using tzwhere package time zone is identified and returned to the user for the requested place