MapPoint Find Sample

 

July 2004

Applies to:
   Microsoft MapPoint 2002
   Microsoft MapPoint 2004

Summary: Learn about the MapPoint Find sample, which uses the MapPoint ActiveX control to replicate the find address, find place and data, and find latitude and longitude functionality of the MapPoint CD-ROM product. (9 printed pages)

Click here to download the code sample for this article.

Contents

Introduction
Code for Find Sample

Introduction

The MapPoint Find sample uses the Microsoft MapPoint ActiveX control to replicate the find address, find place and data, and find latitude and longitude functionality of the MapPoint CD-ROM product.

This download consists of Microsoft Visual Basic 6.0 project files. To run the sample, open the Project1.vbp file in Visual Basic 6.0 and run the project. When the sample application opens, click Find. Switch between the Address, Place/Data, and Lat/Long tabs to find different types of locations on the map.

Code for Find Sample

The Find sample runs on the following code.

[Visual Basic]
Option Explicit

Public strLocationText As String
Public intTab As Integer

Private Sub Form_Load()
    Dim objMap As MapPointCtl.Map

    Set objMap = Form1.MappointControl1.ActiveMap
    
    ComboCountry.AddItem "Canada"
    ComboCountry.AddItem "United States"
    ComboCountry.ListIndex = 1
    
    ComboState.AddItem "-ANY-"
    ComboState.AddItem "AL-Alabama"
    ComboState.AddItem "AK-Alaska"
    ComboState.AddItem "AZ-Arizona"
    ComboState.AddItem "AR-Arkansas"
    ComboState.AddItem "CA-California"
    ComboState.AddItem "CO-Colorado"
    ComboState.AddItem "CT-Connecticut"
    ComboState.AddItem "DE-Delaware"
    ComboState.AddItem "DC-Dist. of Columbia"
    ComboState.AddItem "FL-Florida"
    ComboState.AddItem "GA-Georgia"
    ComboState.AddItem "HI-Hawaii"
    ComboState.AddItem "ID-Idaho"
    ComboState.AddItem "IL-Illinois"
    ComboState.AddItem "IN-Indiana"
    ComboState.AddItem "IA-Iowa"
    ComboState.AddItem "KS-Kansas"
    ComboState.AddItem "KY-Kentucky"
    ComboState.AddItem "LA-Louisiana"
    ComboState.AddItem "ME-Maine"
    ComboState.AddItem "MD-Maryland"
    ComboState.AddItem "MA-Massachusetts"
    ComboState.AddItem "MI-Michigan"
    ComboState.AddItem "MN-Minnesota"
    ComboState.AddItem "MS-Mississippi"
    ComboState.AddItem "MO-Missouri"
    ComboState.AddItem "MT-Montana"
    ComboState.AddItem "NE-Nebraska"
    ComboState.AddItem "NV-Nevada"
    ComboState.AddItem "NH-New Hampshire"
    ComboState.AddItem "NJ-New Jersey"
    ComboState.AddItem "NM-New Mexico"
    ComboState.AddItem "NY-New York"
    ComboState.AddItem "NC-North Carolina"
    ComboState.AddItem "ND-North Dakota"
    ComboState.AddItem "OH-Ohio"
    ComboState.AddItem "OK-Oklahoma"
    ComboState.AddItem "OR-Oregon"
    ComboState.AddItem "PA-Pennsylvania"
    ComboState.AddItem "RI-Rhode Island"
    ComboState.AddItem "SC-South Carolina"
    ComboState.AddItem "SD-South Dakota"
    ComboState.AddItem "TN-Tennessee"
    ComboState.AddItem "TX-Texas"
    ComboState.AddItem "UT-Utah"
    ComboState.AddItem "VT-Vermont"
    ComboState.AddItem "VA-Virginia"
    ComboState.AddItem "WA-Washington"
    ComboState.AddItem "WV-West Virginia"
    ComboState.AddItem "WI-Wisconsin"
    ComboState.AddItem "WY-Wyoming"
    
    Frame1.Visible = True
    Frame2.Visible = False
    Frame3.Visible = False
    intTab = 1
    
End Sub

Private Sub CancelButton_Click()
    Unload DialogFind

End Sub

Private Sub cmdFindAddress_Click()
    Dim strAddressText As String
    strAddressText = ComboAddress.Text & ", " & _
                    ComboCity.Text & ", " & _
                    ComboState.Text & ", " & _
                    ComboZIPCode.Text & ", " & _
                    ComboCountry.Text
    
    FindQuery 1, strAddressText, ""
End Sub

Private Sub cmdFindPlace_Click()
    Dim strPlaceText As String
    strPlaceText = ComboPlace
    
    FindQuery 2, strPlaceText, ""

End Sub

Private Sub cmdFindLatLong_Click()
    Dim objMap As MapPointCtl.Map
    Dim objLoc As MapPointCtl.Location
    Dim objPushPin As MapPointCtl.Pushpin

    Dim strPlaceText As String
    strPlaceText = ComboPlace
    
    FindQuery 3, TextLatitude, TextLongitude
    
    If CheckPushpin.Value = 1 Then
        strLocationText = ListFindPlaceResults.Text
        
        MsgBox TextLatitude & vbCrLf & TextLongitude
    
        Set objLoc = objMap.Location.Location
        
        '// Create a new pushpin.
        Set objPushPin = objMap.AddPushpin(objLoc, TextLatitude & "|" & TextLongitude)
        
        '// Display the balloon.
        objPushPin.BalloonState = geoDisplayBalloon
        
        '// Change pushpin symbol to one of the standard symbols.
        objPushPin.Symbol = 26
        
        objPushPin.Highlight = True
        objPushPin.Note = "This is the place you selected!"
    End If
  
End Sub

Private Sub ComboAddress_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindAddress.Enabled = True
End Sub

Private Sub ComboCity_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindAddress.Enabled = True

End Sub

Private Sub ComboPlace_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindPlace.Enabled = True

End Sub

Private Sub ComboState_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindAddress.Enabled = True

End Sub

Private Sub ComboZIPCode_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindAddress.Enabled = True

End Sub

Private Sub ListFindAddressResults_Click()
    Dim objMap As MapPointCtl.Map
    Dim objLoc As MapPointCtl.Location
    Dim objPushPin As MapPointCtl.Pushpin

    Set objMap = Form1.MappointControl1.ActiveMap
    Set objLoc = objMap.FindResults(ListFindAddressResults.Text)(1)
    objLoc.GoTo
    
    If CheckPushpin.Value = 1 Then
        strLocationText = ListFindAddressResults.Text
        MsgBox strLocationText
        
        '// Create a new pushpin.
        Set objPushPin = objMap.AddPushpin(objLoc, strLocationText)
        
        '// Display the balloon.
        objPushPin.BalloonState = geoDisplayBalloon
        
        '// Change pushpin symbol to one of the standard symbols.
        '// 26 is a yellow circle.
        objPushPin.Symbol = 26
        
        objPushPin.Highlight = True
        objPushPin.Note = "This is the address you selected!"
    End If
    
End Sub

Private Sub ListFindPlaceResults_Click()
    Dim objMap As MapPointCtl.Map
    Dim objLoc As MapPointCtl.Location
    Dim objPushPin As MapPointCtl.Pushpin

    Set objMap = Form1.MappointControl1.ActiveMap
    Set objLoc = objMap.FindPlaceResults(ListFindPlaceResults.Text)(1)
    objLoc.GoTo
    
    If CheckPushpin.Value = 1 Then
        strLocationText = ListFindPlaceResults.Text
        
        MsgBox strLocationText
        
        '// Create a new pushpin.
        Set objPushPin = objMap.AddPushpin(objLoc, strLocationText)
        
        '// Display the balloon.
        objPushPin.BalloonState = geoDisplayBalloon
        
        '// Change pushpin symbol to one of the standard symbols.
        '// 26 is a yellow circle.
        objPushPin.Symbol = 26
        
        objPushPin.Highlight = True
        objPushPin.Note = "This is the place you selected!"
    End If
    
End Sub

Private Sub OKButton_Click()
    Unload DialogFind
    
End Sub

Private Sub TabStrip1_Click()
    If TabStrip1.SelectedItem = "Address" Then
        Frame1.Visible = True
        Frame2.Visible = False
        Frame3.Visible = False
        intTab = 1
    ElseIf TabStrip1.SelectedItem = "Place/Data" Then
        Frame1.Visible = False
        Frame2.Visible = True
        Frame3.Visible = False
        intTab = 2
    Else 'Lat/Long
        Frame1.Visible = False
        Frame2.Visible = False
        Frame3.Visible = True
        intTab = 3
    End If
    Me.Caption = "Find"
    
End Sub

Sub FindQuery(FindType As Integer, FindString As String, FindString2 As String)
    Dim objMap As MapPointCtl.Map
    Dim objLoc As MapPointCtl.Location
    Dim objFindResults As MapPointCtl.FindResults
    Dim x As Integer
    
On Error GoTo errhandler

    MsgBox FindString & vbCrLf & FindString2
    
    Set objMap = Form1.MappointControl1.ActiveMap
  
    'objmap.FindAddressResults([Street], [City], [OtherCity], [Region], [PostalCode], [Country])

    Select Case FindType
        Case Is = 1
            Set objFindResults = objMap.FindResults(FindString)
            ListFindAddressResults.Clear
            x = 1
            Do While x <= objFindResults.Count
                Set objLoc = objFindResults.Item(x)
                ListFindAddressResults.AddItem objLoc.Name
               x = x + 1
            Loop
        Case Is = 2
            Set objFindResults = objMap.FindPlaceResults(FindString)
            ListFindPlaceResults.Clear
            x = 1
            Do While x <= objFindResults.Count
                Set objLoc = objFindResults.Item(x)
                ListFindPlaceResults.AddItem objLoc.Name
               x = x + 1
            Loop
        Case Is = 3
            Set objLoc = objMap.GetLocation(FindString, FindString2)
            objLoc.GoTo
    End Select
        
    Me.Caption = " Find : Results = " & x - 1
    
    Exit Sub

errhandler:
    MsgBox "Problem in Find."
    
End Sub

Private Sub TextLatitude_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindLatLong.Enabled = True

End Sub

Private Sub TextLongitude_Change()
    '// Enable the Find button when a field contains alphanumeric data.
    cmdFindLatLong.Enabled = True

End Sub