
406
|
Chapter 7, Names and Places
#80 Automatically Geocode U.S. Addresses
HACK
Geocoding with the RDF/REST Interface
REST stands for “Representational State Transfer” and is a way to treat web-
services requests as parameters to standard GET and POST requests. This
means that you enter a normal human-readable URL. To make a RESTful
request to the geocoder, you need to create a URI-safe version of the
address. The address needs to be converted to a form that can appear on the
address line of your browser (which means replacing spaces with
+ signs and
using special escape sequences). Here is an example of a RESTful call. The
advantage over the XML-RPC version is that you can paste this directly into
your browser, so there is no need for XML parsing libraries:
http://rpc.geocoder.us/service/rest?address=1005+Gravenstein+Hwy+N+
sebastopol+ca
This returns an RDF/XML document that includes the results of your
request, which will be displayed in different ways depending on your
browser. Apple’s Safari browser displays the full RDF/XML document, as
shown in Figure 7-3.
Older or non-RDF-aware browsers will ignore the tags that they don’t recog-
nize (such as
<geo:Point>), leaving just the coordinates. Opera reveals the
bare coordinates:
-122.842232 38.411908
Here’s an example of a simple program to script the REST interface with
Perl:
#!/usr/bin/perl
use LWP::Simple;
use URI::Escape;
Figure 7-3. The results of a REST-ful ...