我知道如何使用geopy将单个地址转换为GPS坐标,但是我的代码出现问题,应该从文件中逐行读取地址并将每个地址转换为GPS坐标并打印出来。
from geopy.geocoders import Nominatim
geolocator = Nominatim()
f = open("FILE PATH")
line = f.readline()
for line in f.readlines():
address = line
location = geolocator.geocode(address)
print((location.latitude, location.longitude))
f.close()
答案 0 :(得分:1)
这对我有用。
from geopy import Nominatim
geolocator = Nominatim()
with open("addresses",'r') as fp:
for line in fp:
location = geolocator.geocode(line)
print (location.latitude, location.longitude)
fp.close()