WI.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:CAM2RetrieveData 作者: PurdueCAM2Project 项目源码 文件源码
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;
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号