Graphics Programs Reference
In-Depth Information
useFuL geocodIng TooLs
a
Geocoder.us,
http://geocoder.us —Provides a straightforward
interface to copy and paste location to get latitude and longitude.
Also provides an API.
Latitude Longitude Popup,
a
www.gorissen.info/Pierre/maps/ —Google
Maps' mashup. Click a location on the map, and it gives you latitude
and longitude.
Geopy,
a
http://code.google.com/p/geopy/ —Geocoding toolbox for
Python. Wraps up multiple geocoding APIs into a single package.
Visit the Geopy project page for instructions on how to install the package.
There are also lots of straightforward examples on how to start. The fol-
lowing example assumes you have already installed the package on your
computer.
After you install Geopy, download location data at http://book.flowingdata
.com/ch08/geocode/costcos-limited.csv . This is a CSV file that contains the
address of every Costco warehouse in the United States, but it doesn't
have latitude or longitude coordinates. That's up to you.
Visit http://code
.google.com/apis/
maps/signup.html
to sign up for a
free API key for
the Google Maps
API. It's straight-
forward and takes
only a couple of
minutes.
Open a new file and save it as geocode-locations.py . As usual, import the
packages that you need for the rest of the script.
from geopy import geocoders
import csv
You also need an API key for each service you want to use. For the pur-
poses of this example, you only need one from Google.
Store your API key in a variable named g_api_key , and then use it when you
instantiate the geocoder.
g_api_key = 'INSERT_YOUR_API_KEY_HERE'
g = geocoders.Google(g_api_key)
Load the costcos-limited.csv data file, and then loop. For each row, you
piece together the full address and then plug it in for geocoding.
costcos = csv.reader(open('costcos-limited.csv'), delimiter=',')
next(costcos) # Skip header
# Print header
Search WWH ::




Custom Search