MapPoint 2002 includes an ActiveX control, Microsoft
MapPoint Control 9.0, that provides a convenient way to use MapPoint 2002
functionality on a Visual Basic form. A map that you create by using this
control may be saved as a MapPoint file (.ptm), but not as an HTML file. To
create an HTML file from a map, you can automate MapPoint 2002 to copy a .ptm
file-format map to an HTML file that can be accessed by using a Web
browser.
This article provides sample code that shows you how to
create a map by using the MapPoint 2002 control on a Visual Basic form and how
to automate MapPoint 2002 to export the map file to HTML.
In Visual Basic 6.0, create a Standard EXE
project.
Form1 is created by default.
Size Form1 so that it fills the maximum available space
both vertically and horizontally.
On the Project menu, click
References. Select the Microsoft MapPoint 9.0 Object
Library (North America) and then click OK.
Add a MapPoint control and three CommandButton controls to
Form1.
Size the MapPoint control so that it fills as much of Form1
as possible. Leave room for the CommandButton controls.
Set the Caption property for Command1 to Make Route Map, the Caption property for Command2 to Export Map as HTML, and
the Caption property for Command3 to Close the
Project.
Add the following code to the code module of the form:
Public oApp As mappointctl.Application
Public oMap As mappointctl.Map
Public oRoute As mappointctl.Route
Public oWaypoints As mappointctl.Waypoints
Public oResults As mappointctl.FindResults
Public StartPoint As mappointctl.Waypoint
Public MidPoint1 As mappointctl.Waypoint
Public MidPoint2 As mappointctl.Waypoint
Public EndPoint As mappointctl.Waypoint
Public oRootApp As MapPoint.Application
Private Sub Command1_Click()
Set oMap = MappointControl1.ActiveMap
Set oRoute = oMap.ActiveRoute
Set oWaypoints = oRoute.Waypoints
Set oResults = oMap.FindAddressResults("16011 N.E. 36th Way", "Redmond", "", "WA", "98052", 244)
If oResults.Count >= 1 Then
Set StartPoint = oWaypoints.Add(oResults.Item(1), "Loc1")
End If
Set oResults = oMap.FindAddressResults("11235 SE 6th Street", "Bellevue", "", "WA", "98004", 244)
If oResults.Count >= 1 Then
Set MidPoint1 = oWaypoints.Add(oResults.Item(1), "Loc2")
End If
oRoute.Calculate ' This is leg 1
Dim dLeg1 As Double
dLeg1 = oRoute.DrivingTime
' End Leg 1.
Set oResults = oMap.FindAddressResults("22011 SE 51st Street", "Issaquah", "", "WA", "98027", 244)
If oResults.Count >= 1 Then
Set MidPoint2 = oWaypoints.Add(oResults.Item(1), "Loc3")
End If
oRoute.Calculate
Dim dElapsedTime1 As Double
dElapsedTime1 = oRoute.DrivingTime
Dim dLeg2 As Double
dLeg2 = dElapsedTime1 - dLeg1
' End trip time to this waypoint, and Leg 2 drive time.
Set oResults = oMap.FindAddressResults("16011 N.E. 36th Way", "Redmond", "", "WA", "98052", 244)
If oResults.Count >= 1 Then
Set EndPoint = oWaypoints.Add(oResults.Item(1), "Loc1")
End If
oRoute.Calculate
Dim dElapsedTime As Double
Dim dLeg3 As Double
dElapsedTime = oRoute.DrivingTime
dLeg3 = dElapsedTime - dElapsedTime1
' End trip to third waypoint and Leg 3.
Dim StartDate As Double 'DateTime
Dim Mid1Date As Double 'DateTime
Dim Mid2Date As Double 'DateTime
Dim EndDate As Double 'DateTime
Dim StopTime As Double
StopTime = 0.3 * geoOneHour
StartDate = TimeValue("8:00:00 AM")
StartPoint.PreferredDeparture = StartDate
Mid1Date = StartDate + dLeg1 + StopTime
MidPoint1.PreferredDeparture = Mid1Date
Mid2Date = Mid1Date + dLeg2 + StopTime
MidPoint2.PreferredDeparture = Mid2Date
MappointControl1.SaveMapAs FileName:="C:\Atestmap.ptm"
MappointControl1.ActiveMap.Saved = True
End Sub
Private Sub Command2_Click()
Set oRootApp = CreateObject("Mappoint.application")
oRootApp.OpenMap "C:\Atestmap.ptm"
oRootApp.ActiveMap.SaveAs "C:\Atestmap.htm", geoFormatHTMLMapAndDirections
End Sub
Private Sub Command3_Click()
If Not (oRootApp Is Nothing) Then
oRootApp.ActiveMap.Saved = True
oRootApp.Quit
Set oRootApp = Nothing
End If
If Not (oMap Is Nothing) Then
oMap.Saved = True
MappointControl1.Visible = False
Set oApp = Nothing
Set oMap = Nothing
Set oRoute = Nothing
Set oWaypoints = Nothing
Set oResults = Nothing
Set StartPoint = Nothing
Set MidPoint1 = Nothing
Set MidPoint2 = Nothing
Set EndPoint = Nothing
End If
Unload Me
End Sub
Private Sub Form_Load()
MappointControl1.NewMap (geoMapNorthAmerica)
End Sub
To test the program, follow these steps:
Press F5 to run the program.
Click Make Route Map.
After the map displays the route, click Export
Map as HTML and then click Close the
Project.
For
additional information about a Visual Basic .NET version of this article, click
the following article number to view the article in the Microsoft Knowledge
Base:
302897
(http://support.microsoft.com/kb/302897/EN-US/
)
HOW TO: Automate the MapPoint 2002 Control and Save the Map as HTML in Visual Basic .NET
For additional
information about a Microsoft C# version of this article, click the following
article number to view the article in the Microsoft Knowledge Base:
302898
(http://support.microsoft.com/kb/302898/EN-US/
)
HOW TO: Automate the MapPoint 2002 Control and Save the Map as HTML In Visual C# .NET