Reputation: 5396
I know how to use geopy to convert a single address to GPS coordinates, but am having trouble with my code which should read addresses line by line from a file and convert each one to GPS coordinates and print them out.
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()
Upvotes: 0
Views: 10811
Reputation: 217
This worked for me.
from geopy import Nominatim
import time
geolocator = Nominatim()
with open("addresses",'r') as fp:
for line in fp:
location = geolocator.geocode(line)
# print (location.latitude, location.longitude)
time.sleep(1)
Upvotes: 2