# -*- coding: utf-8 -*- # requires http://py-googlemaps.sourceforge.net/ from googlemaps import GoogleMaps import time class apartment: def __init__(self, aptname='', aptaddress=''): self.name = aptname self.address = aptaddress ApartmentList = [] def addapt(aptname, aptaddress): newapt = apartment(aptname,aptaddress) ApartmentList.append(newapt) ### Apartment Names and Addresses go here: addapt("Park Place","850 Quincy St. Washington, DC 20011") addapt("Belmont Crossing","4201 7th St. SE Washington, DC 20032") addapt("Park Triangle Apartments Lofts and Flats","1375 Kenyon St. NW Washington, DC 20010") addapt("Wingate Tower & Garden Apartments","4660 Martin Luther King Jr. Ave. SW Washington, DC 20032") ### OK stop it api_key = "PUT YOUR GOOGLE MAPS API KEY HERE" gmaps = GoogleMaps(api_key) work = '1600 Pennsylvania Avenue NW Washington, DC 20500' for apt in ApartmentList: dirs = gmaps.directions(work, apt.address) dist = float(dirs['Directions']['Distance']['meters']) miles = dist * (0.000621371192) print "%s is %s miles away from the office." % (apt.name, miles) time.sleep(0.5) #used so as not to trigger the Google Maps API rate limiting with large #'s of apts.