212 Part III — Google Map Hacks
entitylist();
}
elsif(param(‘m’) eq ‘getmarkers’)
{
getmarkers(param(‘entity’));
}
The entitylist()function returns a list of unique entity types (restaurants, banks, and so
on) that were populated when the database was populated. For that, the SQL statement uses
DISTINCTto get a list of unique types and then formats XML for the Google Maps applica-
tion to extract:
sub entitylist
{
my $sth = $dbh->prepare(‘select distinct(type) from ch11’);
$sth->execute();
print “<types>”;
while (my $row = $sth->fetchrow_hashref())
{
printf(‘<type typename=”%s”/>’,ucfirst($row->{type}));
}
print “</types>”;
}
The getmarkers()function is just a minor alteration from the script in Chapter 9.
sub getmarkers
{
my ($entity) = @_;
print(“<markers>\n”);
my $sth = $dbh->prepare(sprintf(‘select * from ch11 where type = %s’,
$dbh->quote($entity)));
$sth->execute();
while (my $row = $sth->fetchrow_hashref())
{
printf(‘<marker lat=”%f” lng=”%f” title=”%s”> ;
<infowindow><title>%s</title><address>%s</address><city>%s</city> ;
<phone>%s</phone></infowindow></marker>’,
$row->{lat},
$row->{lng},
$row->{title},
$row->{title},
$row->{adda},
$row->{addb},
$row->{tel},
);
}