我的脚本如下
import numpy as np
import pandas as pd
import geopy
from geopy.geocoders import Nominatim
def getLocationByGeo(cityname):
try:
geolocator = Nominatim(user_agent='my-application')
location = geolocator.geocode(cityname)
lat = location.latitude
lng = location.longitude
return (lat,lng)
except:
# except unrecoginisable address
pass
运行此文件时,我可以成功获取坐标。
Copenhagen (55.6867243, 12.5700724)
Dublin (53.3497645, -6.2602732)
Dubrovnik (42.6499638, 18.0936953)
Dulles international (38.9522097, -77.4534242937754)
Edinburgh (55.9521476, -3.1889908)
但是当运行另一个文件时,我无法获取坐标。
Gatwick
Heathrow
Heathrow Airport
Heathrow T5
Hotel
Kings Cross
London Kings Cross
Copenhagen
我很困惑,就像在第一个文件中一样,我可以得到例如“哥本哈根”坐标,而在第二个文件中,我可以使用示例代码,但是甚至不能“哥本哈根”坐标?