Gecoding REST
Geocoding is installed. Now to create a REST interface I can use from XML.
My most recent survey of Perl XML land revealed XML::Dumper, which is an awful lot like Data::Dumper, but it dumps XML instead of Perl source code. Easy.
I don’t care about the semantics of the document. It doesn’t get my panties in a bunch to see <arrayref/> and <perldata/> in resulting document. The document is small, and it will be consumed directly.
I can use XML::Dumper to dump the result of the function call to Geo::Coder::US, and this is done. I can use this script anywhere in XSLT 2.0 with a call to document.
document(’http://thinknola.com/cgi-bin/geocode?8300+Explanade,+New+Orleans,+LA’)
Start with a CGI refresher.
#!/tno/bin/perl
use CGI;
my $cgi = new CGI();
print $cgi->header("text/xml");
print "<document>@{[ CGI::unescape($ENV{QUERY_STRING}) ]}</document>";
This will spit out the CGI query string, unescaped, inside a tiny XML document. Given a URI like the following…
http://thinknola.com/cgi/geocode?3308+Esplanade,+New+Orleans,+LA
I get a this result document.
Now I can feed that to Geo::Coder::US, and feed the result to XML::Dumper.
#!/tno/bin/perl
use CGI;
use XML::Dumper;
use Geo::Coder::US;
use strict;
Geo::Coder::US->set_db("/tno/var/geo/geocode.db");
my $address = CGI::unescape($ENV{QUERY_STRING} || '');
my @matches = Geo::Coder::US->geocode($address);
my $dump = new XML::Dumper;
my $cgi = new CGI();
print $cgi->header("text/xml");
print $dump->pl2xml(@matches);
You can try for yourself, but if you decide to use it as a service, I’ll have to shut it down to the public.
http://thinknola.com/cgi/geocode?3308+Esplanade,+New+Orleans,+LA.
July 26th, 2006 at 11:42 pm
[…] My gecoding experiences start here and end with a REST interface for Geocoding. […]