Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

174 Part III — Google Map Hacks


Listing 9-20: Updating the onLoad() Function

function onLoad() {
if (GBrowserIsCompatible()) {
infopanel = document.getElementById(“infopanel”);
message = document.getElementById(“message”);
map = new GMap(document.getElementById(“map”));
map.centerAndZoom(new GPoint(-2.944336,53.644638), 10);
map.addControl(new GSmallZoomControl());
showcitylist();
}
}

That completes the JavaScript functionality. The next part of the application is the CGI script
that generates the XML used by this application.

Generating the XML on the Backend.


Listing 9-21 is an adaptation of the earlier XML generation scripts. Remember that the script
now needs to return two different pieces of information: a list of cities and a list of restaurants
within a given city. Both operations are triggered through certain CGI parameters specified by
the URL reference in the JavaScript component that wants to load the XML.

Listing 9-21: Generating the Necessary XML

#!/usr/bin/perl

use DBI;
use strict;
use CGI qw/:standard/;

print header(-type => ‘text/xml’);

my $dbh = DBI->connect( ‘dbi:mysql:database=mapsbookex;host=db.maps.mcslp.com’,
‘mapsbookex’,
‘examples’,
);

if (!defined($dbh))
{
die “Couldn’t open connection to database\n”;
}

if (param(‘m’) eq ‘citylist’)
{
citylist();
Free download pdf