Update! Do not use this for commercial purposes or you will be violating the MapBlast Terms of Use.
Several people wanted an easier way to get maps to some places. So with a little help from my good friends Perl, Win32::OLE and DBI, I was able to write a script to help them out. But first I had to create a database of locations (loc_id, name, address1, city, state, zip).
It is a command line script.
Usage: mapit.pl 134849 134919
This would access our database and get the address of both places. It would then tell IE to navigate to MapBlast and generate a map from the first to the second. I have chosen 0 to represent my current location. So you could run it: mapit.pl 0 134919 to get a map from here to location #134919. It is also possible to run it with one location number to have it generate a destination map.
I give you Map It! (name just picked... may already be taken.)
#/usr/bin/perl -w use strict; use Win32::OLE; use DBI; # start IE my $ie = Win32::OLE->new('InternetExplorer.Application') or die("IE di +dn't start"); # create some variables that will be used in the creation of error mes +sages my $header = qq(<html><head><title>Map It!</title></head><body><h1 ali +gn="center">Map It!</h1>); my $usage = qq(<p><b>Usage:</b> $0 (location #1) [location #2]<br />Ma +p It! will return a map showing how to get from location #1 to locati +on #2.<br />However location #2 can be omitted to receive just a dest +ination map.</p><p><b>Examples:</b><br /><tt>$0 134898</tt> will get +a destination map for location 134989.<br /><tt>$0 0 134898</tt> will + get a route map from here to location 134898.</p><p>This example sho +ws using 0 to represent wherre I am. It can be used as the start or +end point.</p>); my $nodata = qq(<p><b>Location Not Found!</b></p><p>Check the location + numbers again.</p>); my $footer = qq(</body></html>); # get our location numbers my @loc = @ARGV; # how many were given? my $locs = @loc; # Make IE visible $ie->{Visible}=1; # If the wrong number of locations is given, show the usage message if ($locs == 0 || $locs > 2) { Error($ie,$header,$usage,$footer); } else { # setup the database stuff my $db = "database"; my $db_engine = "mysql"; my $host = "localhost"; my $user = "username"; my $password = "password"; my $dbh = DBI->connect("DBI:$db_engine:$db:$host",$user, $password,{ + PrintError => 0}) || die $DBI::errstr; my $table = "locations"; my $select = "name, address1, city, state, zip"; # our arrays to hold locations' address info for later my (@street, @csz); foreach my $loc (@loc) { # if $loc is 0, it's here... so skip the database stuff if ($loc == 0) { push(@street, "123 Main St"); # your street address push(@csz, "90210"); # your zip code next; } my $where = "loc_id = $loc"; my $sql = "SELECT $select FROM $table WHERE $where;"; my $sth = $dbh->prepare($sql); if (!$sth) { die "sth error:" . $dbh->errstr . "\n"; } if (!$sth->execute) { die "sth execute error:" . $sth->errstr . "\n"; } my $ref = $sth->fetchrow_hashref; # if $$ref{address1} doesn't exist, give an error message and die if (!exists $$ref{address1}) { Error($ie,$header,$nodata,$footer); die("$loc doesn't exist"); } # add the street address push(@street, $$ref{address1}); # and zip code if known, otherwise city and state push(@csz, ($$ref{zip} || "$$ref{city},$$ref{state}")); $sth->finish(); } $dbh->disconnect(); my $url; if ($locs == 1) { # if there was only one location number given, i +t's a destination only map $url="http://www.mapblast.com/myblast/map.mb?CMD=GEO&CT=&IC=&LV=" ."&GMI=&GAD1=&GAD2=&GAD3=&GAD4=&AD2=$street[0]&noPrefs=&req_action=" ."crmap&skip=&serch=&PHONE=&noBRP=&remLoc=&AD4=USA&AD2_street=$street[ +0]" ."&AD3=$csz[0]&apmenu=&apcode=&x=67&y=11&selCategory="; } else { # otherwise, it's a route map $url = "http://www.mapblast.com/myblast/driveSilo.mb?&AD4=USA&locB +oxNum=" ."&req_action=getdir&AD2=&AD3=&formnum=2&forceAddr=&CT=&GMI=" ."&multiIC=::::&locn_ckieVal=&serch=&skip=&MA=1&LV=11&CMD=FILL"; for my $i (1..2){ $url .= "&remLoc_$i=&AD4_$i=US&apmenu_$i=&apcode_$i=&GAD1_$i=&GA +D2_$i=&GAD3_$i=" ."&GAD4_$i=&phone_$i=&IC_$i=&GMI_$i="; } $url .= "&AD2_street_1=$street[0]&AD2_1=$street[0]&AD3_1=$csz[0]&A +D2_street_2=" ."$street[1]&AD2_2=$street[1]&AD3_2=$csz[1]"; } $ie->Navigate($url); } sub Error { my ($ie,$header,$error,$footer) = @_; $ie->Navigate(''); my $idoc = $ie->{Document}; $idoc->open("text/html","replace"); $idoc->writeln($header.$error.$footer); }
I could use some more comments but there are enough of them to give you a good idea of what is going on!
Update: I forgot to mention that this particular script only works in the United States. However, it would be a very simple task to make it work elsewhere. Just remember that as of right now, MapBlast will not map from one country to another.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Map It!
by Mr. Muskrat (Canon) on Sep 09, 2002 at 15:40 UTC |