Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

266 Part III — Google Map Hacks


Database Structure.


The application stores routes, and for each route there are two distinct sets of information. The
first is the basic information about the route (the name and description). A route ID will be
added so that you have a unique identifier for the route.

That route table (called ch13_routesimplefor the purposes of this example) will be linked
by the unique route ID to another table that contains the list of points. The table consists of
the route ID, the latitude and longitude of each point, and a unique sequence ID.

Basic Wrapper


The core of the CGI backend is the wrapper. The wrapper includes the interface to the
database. It also controls how communication between the JavaScript components and the
backend work to exchange information, such as route submissions, requests for lists of routes,
and individual route information.

For that there is a simple wrapper, as in previous examples, that initiates the connection to the
database and then extracts requests through the CGI interface and makes calls to the right
function to perform the desired option. The code for this follows:
#!/usr/bin/perl

use DBI;
use Math::Trig;
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 ‘saveroute’)
{
saveroute();
}
if (param(‘m’) eq ‘delroute’)
{
delroute(param(‘routeid’));
}
elsif(param(‘m’) eq ‘listroutes’)
{
listroutes();
}
Free download pdf