Chapter 9 — Using Overlays 153
Listing 9-3:An XML Version of the Data
#!/usr/bin/perl
my $points = [
{x => -0.6394,
y => 52.9114,
title => ‘China Inn’},
{x => -0.64,
y => 52.909444,
title => ‘One on Wharf’},
{x => -0.64454,
y => 52.91066,
title => ‘Hop Sing’},
{x => -0.642743,
y => 52.9123959,
title => ‘Nicklebys’},
{x => -0.6376,
y => 52.9073,
title => ‘Siam Garden’},
];
print ‘
foreach my $point (@{$points})
{
printf(‘
$point->{y},
$point->{x},
$point->{title});
}
print ‘’;
Running this script will generate an XML document to the standard output, which you can
redirect into a suitable file.
You might want to use an XML library to generate the XML that is used in your Google Maps
applications. Although generating the XML by hand is an acceptable way to generate the data,
it can lead to problems because of a simple typographical error. That said, some XML generation
libraries can make the process more complicated and in some cases may simply be unable to cre-
ate the complexity of document that you want if you are generating information from a
database or non-linear data source.
Loading and parsing the file is a multi-stage process, starting with creating a suitable
GXmlHttpobject — a class exposed by the Google Maps API for loading remote HTTP:
var request = GXmlHttp.create();