如何在 python 中获取地址并生成纬度、经度坐标?我有一些地址想要获取经纬度,但似乎不起作用。
我使用了 geopandas 但它没有给我带来任何回报。我也对user_agent使用什么感到有点困惑。这是我的代码,
import pandas as pd
from geopy.geocoders import Nominatim
df2['location_lat'] = ""
df2['location_long'] = ""
geolocator = Nominatim(user_agent="myApp")
for i in df2.index:
try:
#tries fetch address from geopy
location = geolocator.geocode(df2['Location'][i])
#append lat/long to column using dataframe location
df2.loc[i,'location_lat'] = location.latitude
df2.loc[i,'location_long'] = location.longitude
except:
#catches exception for the case where no value is returned
#appends null value to column
df2.loc[i,'location_lat'] = ""
df2.loc[i,'location_long'] = ""
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。谢谢。