def gAPI(locat,hwy, city, link, f): #Location is discription ,city, link is to URL, f is file
time.sleep(0.2);
geolocator = GoogleV3()
try:
searchTerm = str(locat + ',' + city + ', WI, US') #Search for location and city
location = geolocator.geocode(searchTerm)
except:
try:
searchTerm = str(hwy + ',' + city + ', WI, US') #Search for hwy and city
location = geolocator.geocode(searchTerm)
except:
searchTerm = str(city + ', WI, US') #Search for only city
location = geolocator.geocode(searchTerm)
extractCity = location.raw['address_components'] #Get the raw JSON information so that the city name can be extracted
for item in extractCity:
types = item['types']
if types[0] == "locality":
city = item['long_name']
# print locat, hwy, city
# print location.latitude, location.longitude
locat = 'USA'+'#'+'WI'+'#'+str(city)+'#'+link+'#'+str(location.latitude)+'#'+str(location.longitude)
f.write(locat.encode('utf-8').replace(" ","").replace("\n",'')+'\n')
return;
评论列表
文章目录