Geopy 输出 NoneType

Geopy outputs NoneType

我想用geopy获取地址的经纬度。我的密码是

geolocator = Nominatim(user_agent="EXAMPLE")
location = geolocator.geocode("Wismarsche Straße 393-397 19049 Schwerin")
lat = str(location.latitude)
lon = str(location.longitude)
latLon = str(lat) + ";" + str(lon) + ";"

并输出 NoneType.

有人知道为什么吗?

documentation 声明地理编码方法 returns None 未找到结果时。在您的情况下,从查询中删除 19049 returns 结果:

location = geolocator.geocode("Wismarsche Straße 393-397 Schwerin")
lat = str(location.latitude)
lon = str(location.longitude)
latLon = str(lat) + ";" + str(lon) + ";"

print(f'Latitude: {lat}, longitude: {lon}, latLon: {latLon}')

输出:

Latitude: 53.6519479, longitude: 11.4073671, latLon: 53.6519479;11.4073671;