
Track a Package Across the U.S. #86
Chapter 7, Names and Places
|
431
HACK
Working with them quickly transforms your project from a hack into a full-
scale software development effort.
Instead of making use of the programming APIs of the major shippers, we’ll
use a much older hacking technique: copy and paste. Look up your pack-
age’s tracking information in the usual way. Then create a text file listing the
city and state of each location in chronological order, and save it in a file
named places.txt. Your file should look something like this:
Seattle, WA
Austin, Texas
Chicago, Illinois
Boston, Massachusetts
Medford, Massachusetts
Now we’re ready to map these locations. To do this, we’ll need to translate
our list of place names into a list of geographic coordinates, which is a job
we already tackled in “Geocode U.S. Locations with the GNIS”
[Hack #85],
which leverages a U.S. Geological Survey database of places for this purpose.
The Code
PackageTracker.java is a Java program that can be run from the command
line. It knows how to read the little place-name text file we created and use
the
GNISCoords class [Hack #85] for geocoding the entries. It can write the new
information to disk, or simply to stdout, which can be piped into other
applications on Unix-ish operating systems like Mac OS X, Linux, and
Solaris. For our purposes, write it to disk so that our mapping program can
find it.
The program is too