#! perl -lw
use munge_address;

open GPS,"database" or die;
$_=<GPS>;
while(<GPS>){
    next if /^latitude/;
    die $_ unless /^([0-9.]+),(-[0-9.]+),"(.*)"/;
    $lat=$1;$long=$2,$gadd=$3;
    $coords{$gadd}="$long,$lat";
}

while(<>){
    s/<font[^>]+?>//g;
    s,</font>,,g;
    die unless ($name,$address,$city,$state,$zip)=m,^\s+<td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td align="center">(.*?)</td><td>(.*?)<,;
    $name =~ s/\s+$//;

    $original=$address;
    $address=&munge_address::munge_address($address);
    $lookup= "$address, $city, $state $zip" ;
    die unless defined ($c=$coords{$lookup});

    print "<Placemark><name>$name</name><description>$original, $city, $state $zip</description><Point><coordinates>$c,0</coordinates></Point></Placemark>";
}
