Showing posts with label mappoint. Show all posts
Showing posts with label mappoint. Show all posts

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");
$Route->Waypoints->Add($Results1->Item(1));
my $Results2 = $Map->FindResults("End Address");
$Route->Waypoints->Add($Results2->Item(1));
$Route->Calculate;
my $distance;
for ($count=1; $count<$Route->Directions->Count; $count++)
{
print $Route->Directions->Item($count)->Instruction . " ";
$distance=$Route->Directions->Item($count)->Distance;
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;

Blog Archive