Microsoft KB Archive/302885

= HOWTO: Use the MapPoint 2002 Control and Automation with Visual Basic to Save a Map as HTML =

Article ID: 302885

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft MapPoint 2002 Standard Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q302885



SUMMARY
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.



MORE INFORMATION
 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(&quot;16011 N.E. 36th Way&quot;, &quot;Redmond&quot;, &quot;&quot;, &quot;WA&quot;, &quot;98052&quot;, 244) If oResults.Count >= 1 Then Set StartPoint = oWaypoints.Add(oResults.Item(1), &quot;Loc1&quot;) End If

Set oResults = oMap.FindAddressResults(&quot;11235 SE 6th Street&quot;, &quot;Bellevue&quot;, &quot;&quot;, &quot;WA&quot;, &quot;98004&quot;, 244) If oResults.Count >= 1 Then Set MidPoint1 = oWaypoints.Add(oResults.Item(1), &quot;Loc2&quot;) End If       oRoute.Calculate ' This is leg 1 Dim dLeg1 As Double dLeg1 = oRoute.DrivingTime ' End Leg 1. Set oResults = oMap.FindAddressResults(&quot;22011 SE 51st Street&quot;, &quot;Issaquah&quot;, &quot;&quot;, &quot;WA&quot;, &quot;98027&quot;, 244) If oResults.Count >= 1 Then Set MidPoint2 = oWaypoints.Add(oResults.Item(1), &quot;Loc3&quot;) 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(&quot;16011 N.E. 36th Way&quot;, &quot;Redmond&quot;, &quot;&quot;, &quot;WA&quot;, &quot;98052&quot;, 244) If oResults.Count >= 1 Then Set EndPoint = oWaypoints.Add(oResults.Item(1), &quot;Loc1&quot;) 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(&quot;8:00:00 AM&quot;) StartPoint.PreferredDeparture = StartDate Mid1Date = StartDate + dLeg1 + StopTime MidPoint1.PreferredDeparture = Mid1Date Mid2Date = Mid1Date + dLeg2 + StopTime MidPoint2.PreferredDeparture = Mid2Date MappointControl1.SaveMapAs FileName:=&quot;C:\Atestmap.ptm&quot; MappointControl1.ActiveMap.Saved = True End Sub

Private Sub Command2_Click Set oRootApp = CreateObject(&quot;Mappoint.application&quot;) oRootApp.OpenMap &quot;C:\Atestmap.ptm&quot; oRootApp.ActiveMap.SaveAs &quot;C:\Atestmap.htm&quot;, 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 </li> To test the program, follow these steps: <ol style="list-style-type: lower-alpha;"> Press F5 to run the program.</li> Click Make Route Map.</li> After the map displays the route, click Export Map as HTML and then click Close the Project.</li> Start your Web browser and open C:\Atestmap.htm.</li></ol> </li></ol>

<div class="references_section">