我试图反转地理编码坐标并使用geopy检索相应的国家/地区代码.但是,Geopy似乎没有提供获取国家/地区代码的方法.所以,我首先尝试检索国家/地区名称,然后将它们转换为代码.不幸的是,我的代码为我提供了非英语语言的国家/地区名称.
如何用英语获取国家/地区名称?
我的代码:
geolocator = Nominatim()
....
with open('coordinates.txt' , 'r') as readfile:
for line in readfile:
fields = line.split("\t")
address, (latitude, longitude) = geolocator.reverse(fields[1]+","+fields[2])
if address:
address = address.split(",")
print "%s" % (address[-1])
Run Code Online (Sandbox Code Playgroud)
我得到的输出:
??????
???????
Türkiye
Shqipëria
Tanzania
????? Ethiopia
Bosna i Hercegovina
Türkiye
Shqipëria
România
??????? - Sudan
Run Code Online (Sandbox Code Playgroud)