When you try embedding exactly_one=False
parameter (by default it is True
) into your code, like
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent='[email protected]', timeout=10)
location = geolocator.geocode("Georgia", exactly_one=False)
the result will be a list, where you can observe that 10
OSM-features possess a 'Georgia'
string in them.
[Location(Georgia, United States of America, (32.3293809, -83.1137366,
0.0)), Location(საქართველო, (41.6809707, 44.0287382, 0.0)), Location(Georgia, Franklin County, Vermont, United States of America,
(44.72422295, -73.14704151731551, 0.0)), Location(Georgia, Freehold
Township, New Jersey, 07710, United States of America, (40.1873348,
-74.2845906, 0.0)), Location(Georgia, Lawrence County, Indiana, United States of America, (38.7100521, -86.5722154, 0.0)), Location(Georgia,
Lamar County, Texas, United States of America, (33.7539902,
-95.8313566, 0.0)), Location(Georgia, Hartselle, Morgan County, Alabama, 35640, United States of America, (34.453428, -86.9280617,
0.0)), Location(Georgia, Kingman County, Kansas, 67067, United States of America, (37.6277929, -98.008669, 0.0)), Location(Georgia,
Assumption Parish, Louisiana, 70372, United States of America,
(29.8402049, -90.9884312, 0.0)), Location(Georgia, دبي, United Arab
Emirates, (25.20796335, 55.153055200000004, 0.0))]
When geolocator.geocode("Georgia")
is used, it results in a first element from the list, i.e. Location(Georgia, United States of America, (32.3293809, -83.1137366, 0.0))
.
So, there are several solutions to achieve a country instead of a state.
Using the country_codes="ge"
parameter, a list with two-letter country codes can be found in ISO 3166-1 alpha-2
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent='[email protected]', timeout=10)
location = geolocator.geocode("Georgia", country_codes="ge")
Using country name written in a native language, e.g. for Georgia both 'საქართველო'
or 'Sakartvelo'
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent='[email protected]', timeout=10)
location = geolocator.geocode("საქართველო")
or
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent='[email protected]', timeout=10)
location = geolocator.geocode("Sakartvelo")
Using country name written in a different language, e.g. 'Грузія'
in Ukrainian. As was mentioned by @Kadir Şahbaz in his comment.
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent='[email protected]', timeout=10)
location = geolocator.geocode("Грузія")
Result of print(location.raw)
{'place_id': 235489648, 'licence': 'Data © OpenStreetMap contributors,
ODbL 1.0. https://osm.org/copyright', 'osm_type': 'relation',
'osm_id': 28699, 'boundingbox': ['41.0552922', '43.5864294',
'39.8844803', '46.7365373'], 'lat': '41.6809707', 'lon': '44.0287382',
'display_name': 'საქართველო', 'class': 'boundary', 'type':
'administrative', 'importance': 0.7384537973566208, 'icon':
'https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png';}
References: