Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

150 Part III — Google Map Hacks


Listing 9-2(continued)

var map;
var points = [];
var index = 0;
var infopanel;
EOF
}

sub js_onLoad
{
my @markers;

foreach my $point (@{$points})
{
push @markers,sprintf(“addmarker(%f,%f,’%s’);”,
$point->{x},
$point->{y},
$point->{title});
}

my $template = <<EOF;
function onLoad() {
if (GBrowserIsCompatible()) {
infopanel = document.getElementById(“infopanel”);
map = new GMap(document.getElementById(“map”));
map.centerAndZoom(new GPoint(-0.64,52.909444), 2);
%s
}
}
EOF

printf($template,join(“\n”,@markers));

}

sub js_addmarker
{
print <<EOF;
function addmarker(x,y,title) {
var point = new GPoint(parseFloat(x),parseFloat(y));
points.push(point);
var marker = new GMarker(point);
map.addOverlay(marker);
infopanel.innerHTML = infopanel.innerHTML +
‘<a href=”#” onClick=”movemap(‘ + index + ‘);”>’ +
title +
‘</a><br/>’;
index++;
}
Free download pdf