Microsoft KB Archive/302885

From BetaArchive Wiki
Knowledge Base


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

  1. In Visual Basic 6.0, create a Standard EXE project.

    Form1 is created by default.
  2. Size Form1 so that it fills the maximum available space both vertically and horizontally.
  3. On the Project menu, click References. Select the Microsoft MapPoint 9.0 Object Library (North America) and then click OK.
  4. Add a MapPoint control and three CommandButton controls to Form1.
  5. Size the MapPoint control so that it fills as much of Form1 as possible. Leave room for the CommandButton controls.
  6. 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.
  7. 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
                        
  8. To test the program, follow these steps:
    1. Press F5 to run the program.
    2. Click Make Route Map.
    3. After the map displays the route, click Export Map as HTML and then click Close the Project.
    4. Start your Web browser and open C:\Atestmap.htm.


REFERENCES

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 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 HOW TO: Automate the MapPoint 2002 Control and Save the Map as HTML In Visual C# .NET



Additional query words: mappoint

Keywords: kbhowto kbautomation KB302885