Tuesday, November 3, 2009

MapPoint and Perl. Basic code to get driving directions.

I'm not a perl guru. I dabble. However, this is the code I've been working around to provide automated queries versus a MapPoint install so as not to bother the online web-based map providers with large amounts of queries:

First, you can get a demo of MapPoint 2013 Here ... It's a 14 day fully functional trial except it bugs you to activate every time you start it. Not good for automation, but decent enough if you want to test this.

use Win32::OLE qw(in with);
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft MapPoint';
$Win32::OLE::Warn = 3; # die on errors...

my $MapPoint = Win32::OLE->new('MapPoint.Application', 'Quit');
my $Map = $MapPoint->NewMap();
my $Route = $Map->ActiveRoute();
my $Results1 = $Map->FindResults("Start Address");
my $Results2 = $Map->FindResults("End Address");
my $distance;
for ($count=1; $count<$Route->Directions->Count; $count++)
print $Route->Directions->Item($count)->Instruction . " ";
if ($distance < 0.1) {
printf "%6.2f yds\n", ($distance*1760)
} else {
printf "%6.2f mi\n", $distance;
print $Route->Directions->Item($Route->Directions->Count)->Instruction

$Map->{Saved} = -1;

No comments:

Blog Archive