Solved

Mappoint click on pushpin

Posted on 2006-11-07
8
1,093 Views
Last Modified: 2008-02-07
Hello everybody,

I'm working at a Mappoint application in VB.net which adds and removes pushpins at runtime.
Now I'm searching to find the event which is triggered after clicking on one of these placed pushpins.

Is there anyone who can help me find this event or a sollution for my problem.
Many thanks in advance.
0
Comment
Question by:ACAE
  • 7
8 Comments
 
LVL 5

Accepted Solution

by:
maralans earned 250 total points
ID: 17896687
I have a some Mappoint code that I am happy to post here for you but I don't personnaly use it so I don't know if it is what you are looking for or not.  Let me know and you can look through it if you want and see if it fits your needs.
0
 

Author Comment

by:ACAE
ID: 17897225
Any help is welcome. So please post your code.
Thanks.
0
 
LVL 5

Expert Comment

by:maralans
ID: 17897474
Like I said, I don't use it but hopefully you can find something useful.

Imports System
Imports System.Net
Imports HelloV3OFW.MPNet

Imports System.Drawing
Imports System.Drawing.Design
Imports System.Drawing.Drawing2D
Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public myFindService As New MPNet.FindServiceSoap()
    Public myRenderService As New MPNet.RenderServiceSoap()

    Dim m_pixelWidth As Integer = 500
    Dim m_pixelHeight As Integer = 400

    Dim myViews(0) As MPNet.ViewByHeightWidth

    Dim foundResults As FindResults
    Dim POIPins() As Pushpin

    Dim NumberOfPOI As Integer = 0

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnSearch As System.Windows.Forms.Button
    Friend WithEvents txtLocation As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents tbMapWidth As System.Windows.Forms.TrackBar
    Friend WithEvents pbMap As System.Windows.Forms.PictureBox
    Friend WithEvents tt As System.Windows.Forms.ToolTip
    Friend WithEvents cmbPOI As System.Windows.Forms.ComboBox
    Friend WithEvents lstResults As System.Windows.Forms.ListBox
    Friend WithEvents txtDetails As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents chkDrawLocal As System.Windows.Forms.CheckBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btnRefresh As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.btnSearch = New System.Windows.Forms.Button
        Me.txtLocation = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.tbMapWidth = New System.Windows.Forms.TrackBar
        Me.pbMap = New System.Windows.Forms.PictureBox
        Me.tt = New System.Windows.Forms.ToolTip(Me.components)
        Me.cmbPOI = New System.Windows.Forms.ComboBox
        Me.lstResults = New System.Windows.Forms.ListBox
        Me.txtDetails = New System.Windows.Forms.TextBox
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.btnRefresh = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.chkDrawLocal = New System.Windows.Forms.CheckBox
        CType(Me.tbMapWidth, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.pbMap, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnSearch
        '
        Me.btnSearch.Location = New System.Drawing.Point(202, 28)
        Me.btnSearch.Name = "btnSearch"
        Me.btnSearch.Size = New System.Drawing.Size(76, 27)
        Me.btnSearch.TabIndex = 32
        Me.btnSearch.Text = "Find It!"
        '
        'txtLocation
        '
        Me.txtLocation.Location = New System.Drawing.Point(10, 28)
        Me.txtLocation.Name = "txtLocation"
        Me.txtLocation.Size = New System.Drawing.Size(172, 22)
        Me.txtLocation.TabIndex = 31
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(10, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(86, 19)
        Me.Label1.TabIndex = 30
        Me.Label1.Text = "Search for:"
        '
        'tbMapWidth
        '
        Me.tbMapWidth.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.tbMapWidth.LargeChange = 16
        Me.tbMapWidth.Location = New System.Drawing.Point(735, 9)
        Me.tbMapWidth.Maximum = 400
        Me.tbMapWidth.Minimum = 1
        Me.tbMapWidth.Name = "tbMapWidth"
        Me.tbMapWidth.Orientation = System.Windows.Forms.Orientation.Vertical
        Me.tbMapWidth.Size = New System.Drawing.Size(56, 471)
        Me.tbMapWidth.SmallChange = 4
        Me.tbMapWidth.TabIndex = 29
        Me.tbMapWidth.TickFrequency = 10
        Me.tbMapWidth.TickStyle = System.Windows.Forms.TickStyle.TopLeft
        Me.tbMapWidth.Value = 2
        '
        'pbMap
        '
        Me.pbMap.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pbMap.BackColor = System.Drawing.SystemColors.ControlDark
        Me.pbMap.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pbMap.Location = New System.Drawing.Point(298, 9)
        Me.pbMap.Name = "pbMap"
        Me.pbMap.Size = New System.Drawing.Size(437, 462)
        Me.pbMap.TabIndex = 28
        Me.pbMap.TabStop = False
        '
        'cmbPOI
        '
        Me.cmbPOI.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbPOI.Items.AddRange(New Object() {"None", "Book Stores", "Video Stores"})
        Me.cmbPOI.Location = New System.Drawing.Point(19, 74)
        Me.cmbPOI.Name = "cmbPOI"
        Me.cmbPOI.Size = New System.Drawing.Size(125, 24)
        Me.cmbPOI.TabIndex = 37
        '
        'lstResults
        '
        Me.lstResults.ItemHeight = 16
        Me.lstResults.Location = New System.Drawing.Point(19, 138)
        Me.lstResults.Name = "lstResults"
        Me.lstResults.Size = New System.Drawing.Size(231, 164)
        Me.lstResults.TabIndex = 38
        '
        'txtDetails
        '
        Me.txtDetails.Location = New System.Drawing.Point(19, 360)
        Me.txtDetails.Multiline = True
        Me.txtDetails.Name = "txtDetails"
        Me.txtDetails.Size = New System.Drawing.Size(231, 102)
        Me.txtDetails.TabIndex = 39
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.btnRefresh)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.chkDrawLocal)
        Me.GroupBox1.Controls.Add(Me.cmbPOI)
        Me.GroupBox1.Controls.Add(Me.lstResults)
        Me.GroupBox1.Controls.Add(Me.txtDetails)
        Me.GroupBox1.Location = New System.Drawing.Point(10, 74)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(268, 471)
        Me.GroupBox1.TabIndex = 40
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Points of Interest"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(19, 120)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(115, 18)
        Me.Label4.TabIndex = 44
        Me.Label4.Text = "Listings"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(19, 342)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(115, 18)
        Me.Label3.TabIndex = 43
        Me.Label3.Text = "Details"
        '
        'btnRefresh
        '
        Me.btnRefresh.Location = New System.Drawing.Point(182, 74)
        Me.btnRefresh.Name = "btnRefresh"
        Me.btnRefresh.Size = New System.Drawing.Size(68, 28)
        Me.btnRefresh.TabIndex = 42
        Me.btnRefresh.Text = "Refresh"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(19, 55)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(115, 19)
        Me.Label2.TabIndex = 41
        Me.Label2.Text = "Category"
        '
        'chkDrawLocal
        '
        Me.chkDrawLocal.Checked = True
        Me.chkDrawLocal.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkDrawLocal.Location = New System.Drawing.Point(19, 28)
        Me.chkDrawLocal.Name = "chkDrawLocal"
        Me.chkDrawLocal.Size = New System.Drawing.Size(183, 18)
        Me.chkDrawLocal.TabIndex = 40
        Me.chkDrawLocal.Text = "Draw POI Locally"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
        Me.ClientSize = New System.Drawing.Size(792, 484)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.btnSearch)
        Me.Controls.Add(Me.txtLocation)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.tbMapWidth)
        Me.Controls.Add(Me.pbMap)
        Me.Name = "Form1"
        Me.Text = "MapPoint .NET V3.0 Sample Application"
        CType(Me.tbMapWidth, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.pbMap, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        myFindService.Credentials = New NetworkCredential("userid", "password")
        myRenderService.Credentials = New NetworkCredential("userid", "password")

        cmbPOI.SelectedIndex = 0
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Dim intFound As Integer
        Dim findSpec As New MPNet.FindSpecification()
        Dim myDataSource As New MPNet.DataSource()
        Dim searchResults As MPNet.FindResults

        Try
            findSpec.InputPlace = txtLocation.Text
            findSpec.DataSourceName = "MapPoint.NA"

            searchResults = myFindService.Find(findSpec)

            If Not searchResults Is Nothing Then
                Dim latLong As MPNet.LatLong = New MPNet.LatLong()
                latLong.Longitude = searchResults.Results(0).FoundLocation.LatLong.Longitude
                latLong.Latitude = searchResults.Results(0).FoundLocation.LatLong.Latitude

                ReDim POIPins(0)
                POIPins(0) = New MPNet.Pushpin()
                POIPins(0).Label = searchResults.Results(0).FoundLocation.Entity.DisplayName
                POIPins(0).LatLong = latLong
                POIPins(0).IconDataSource = "MapPoint.Icons"
                POIPins(0).IconName = "33"
                POIPins(0).PinID = "pinid"

                myViews(0) = searchResults.Results(0).FoundLocation.BestMapView.ByHeightWidth

                doPOIQuery()
            End If
        Catch ex As Exception
            Debug.Write(ex.ToString)

        End Try
    End Sub

    Private Sub refreshMap()

        Dim mapSpec As New MPNet.MapSpecification()

        Try
            mapSpec.DataSourceName = "MapPoint.NA"

            m_pixelWidth = pbMap.Width
            m_pixelHeight = pbMap.Height

            mapSpec.Options = New MPNet.MapOptions()
            mapSpec.Options.Format = New MPNet.ImageFormat()
            mapSpec.Options.Format.Height = m_pixelHeight
            mapSpec.Options.Format.Width = m_pixelWidth

            'If we are drawing the points locally, don't pass MapPoint .NET a set of pins
            If chkDrawLocal.Checked = True Then
                mapSpec.Pushpins = Nothing
            Else
                If POIPins.Length >= 99 Then
                    ReDim Preserve POIPins(99)
                End If
                mapSpec.Pushpins = POIPins
            End If

            mapSpec.Views = myViews

            mapSpec.Options.Style = MPNet.MapStyle.DefaultStyle
            mapSpec.Options.FontSize = MapFontSize.Smaller

            Dim mapImages() As MPNet.MapImage
            mapImages = myRenderService.GetMap(mapSpec)

            If chkDrawLocal.Checked = True Then
                Dim newBitmap As Bitmap

                newBitmap = New Bitmap(ClientSize.Width, ClientSize.Height)

                Dim graphics As Graphics
                graphics = Drawing.Graphics.FromImage(newBitmap)


                Dim mapBitmap As Bitmap
                mapBitmap = New Bitmap(New MemoryStream(mapImages(0).MimeData.Bits))

                graphics.DrawImage(mapBitmap, 0, 0)
                DrawPushpins(graphics, POIPins)
                pbMap.Image = newBitmap
            Else
                pbMap.Image = New Bitmap(New System.IO.MemoryStream(mapImages(0).MimeData.Bits))
            End If

        Catch ex As Exception
            Debug.Write(ex.ToString)
        End Try
    End Sub


    Sub doPOIQuery()

        Dim POIDatasourceName As String
        Dim POIEntityTypeName As String

        Select Case cmbPOI.Text
            Case "None"
                ReDim Preserve POIPins(0)
                refreshMap()
                Exit Sub

            Case "Book Stores"
                POIDatasourceName = "Acxiom.US.SIC_G.59"
                POIEntityTypeName = "SIC5942"

            Case "Video Stores"
                POIDatasourceName = "Acxiom.US.SIC_I.78"
                POIEntityTypeName = "SIC7841"
        End Select

        Try
            Dim findNearbySpec As New FindNearbySpecification()
            findNearbySpec.DataSourceName = POIDatasourceName
            findNearbySpec.Distance = 50.0
            findNearbySpec.LatLong = New LatLong()
            findNearbySpec.LatLong = myViews(0).CenterPoint
            findNearbySpec.Filter = New FindFilter()
            findNearbySpec.Filter.EntityTypeName = POIEntityTypeName
            findNearbySpec.Options = New FindOptions()
            findNearbySpec.Options.Range = New FindRange()
            If chkDrawLocal.Checked = True Then
                findNearbySpec.Options.Range.Count = 200
            Else
                findNearbySpec.Options.Range.Count = 99
            End If

            NumberOfPOI = 0
            ReDim Preserve POIPins(NumberOfPOI)
            lstResults.Items.Clear()
            txtDetails.Text = ""

            foundResults = myFindService.FindNearby(findNearbySpec)

            Dim fr As FindResult
            Dim newpin As New Pushpin()

            For Each fr In foundResults.Results
                newpin = New Pushpin()
                NumberOfPOI = NumberOfPOI + 1
                lstResults.Items.Add(NumberOfPOI & ") " & ProperCase(fr.FoundLocation.Entity.Name))

                newpin.Label = ""
                newpin.LatLong = fr.FoundLocation.LatLong
                newpin.IconDataSource = "MapPoint.Icons"
                newpin.IconName = "" & (305 + NumberOfPOI)
                newpin.PinID = "pinid"

                ReDim Preserve POIPins(NumberOfPOI)
                POIPins(NumberOfPOI) = newpin
            Next
            refreshMap()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "An error has occured during Find Nearby.")
        End Try
    End Sub


    Private Sub lstResults_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstResults.SelectedIndexChanged
        Dim fr As FindResult
        Dim nl As String = Chr(13) & Chr(10)

        Dim indx As Integer = lstResults.SelectedIndex
        fr = foundResults.Results(indx)

        txtDetails.Text = "" & (lstResults.SelectedIndex + 1) & ") " & ProperCase(fr.FoundLocation.Entity.Name) & nl

        If Not fr.FoundLocation.Entity.Properties(0).Value Is Nothing Then
            txtDetails.Text = txtDetails.Text & ProperCase(fr.FoundLocation.Entity.Properties(0).Value) & nl
        End If

        Dim tmp As String = ""
        If Not fr.FoundLocation.Entity.Properties(1).Value Is Nothing Then
            tmp = ProperCase(fr.FoundLocation.Entity.Properties(1).Value)
        End If
        If Not fr.FoundLocation.Entity.Properties(2).Value Is Nothing Then
            tmp = tmp & ", " & fr.FoundLocation.Entity.Properties(2).Value
        End If
        If Not fr.FoundLocation.Entity.Properties(3).Value Is Nothing Then
            tmp = tmp & " " & fr.FoundLocation.Entity.Properties(3).Value
        End If

        If tmp <> "" Then
            txtDetails.Text = txtDetails.Text & tmp & nl
        End If

        If Not fr.FoundLocation.Entity.Properties(5).Value Is Nothing Then
            txtDetails.Text = txtDetails.Text & formatPhone(fr.FoundLocation.Entity.Properties(5).Value) & nl
        End If

        myViews(0).CenterPoint = fr.FoundLocation.LatLong
        refreshMap()
    End Sub

    Private Sub DrawPushpins(ByVal graphics As Graphics, ByVal pushpins As Pushpin())

        Dim pen As Pen = New Pen(Color.DarkGray, 2)     'for the POI's outline
        pen.Alignment = PenAlignment.Inset
        Dim brush As SolidBrush = New SolidBrush(Color.DarkRed)    'for the POI's fill

        Dim fontbrush As SolidBrush = New SolidBrush(Color.White)   'for the POI's label

        Dim pen2 As Pen = New Pen(Color.Yellow, 2)     'for the search location's outline
        pen2.Alignment = PenAlignment.Inset
        Dim brush2 As SolidBrush = New SolidBrush(Color.Black)    'for the search location's fill

        Dim font As System.Drawing.Font
        font = New System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Regular)

        Dim font2 As System.Drawing.Font
        font2 = New System.Drawing.Font("Arial", 7, System.Drawing.FontStyle.Regular)

        Dim StringFormat As System.Drawing.StringFormat
        StringFormat = New System.Drawing.StringFormat()

        'Build a set of lat/Long objects from the passed in pushpins
        Dim latLongs(pushpins.Length - 1) As LatLong
        Dim indx As Integer = 0
        Dim thisPin As Pushpin

        For Each thisPin In pushpins
            latLongs(indx) = New LatLong()
            latLongs(indx).Latitude = thisPin.LatLong.Latitude
            latLongs(indx).Longitude = thisPin.LatLong.Longitude
            indx = indx + 1
        Next

        'Convert the lat/Long coords to Pixel Coords
        Dim points(latLongs.Length) As MPNet.PixelCoord
        points = myRenderService.ConvertToPoint _
            (latLongs, myViews(0), m_pixelWidth, m_pixelHeight)

        ' Loop through each Pixel object and draw on the map.
        indx = 1
        Dim p As PixelCoord

        Dim radius As Integer = 9

        For Each p In points
            'The first pin is the search location, not a POI
            'so we'll draw it differently
            If indx = 1 Then
                graphics.DrawEllipse(pen2, p.X - radius, p.Y - radius, radius * 2, radius * 2) 'Draw the outline
                graphics.FillEllipse(brush2, p.X - radius + 1, p.Y - radius + 1, (radius * 2) - 2, (radius * 2) - 2)   'Fill it in
            Else
                graphics.DrawEllipse(pen, p.X - radius, p.Y - radius, radius * 2, radius * 2)  'Draw the outline
                graphics.FillEllipse(brush, p.X - radius + 1, p.Y - radius + 1, (radius * 2) - 2, (radius * 2) - 2) 'Fill it in

                'Calculate the width of the label for the icon
                Dim w As Double
                If indx > 99 Then
                    w = graphics.MeasureString((indx - 1).ToString(), font2, 30, StringFormat).Width
                    w = (w / 2) - 1
                    graphics.DrawString((indx - 1).ToString(), font2, fontbrush, p.X - w, p.Y - radius + 4, StringFormat)
                Else
                    w = graphics.MeasureString((indx - 1).ToString(), font, 30, StringFormat).Width
                    w = (w / 2) - 1
                    graphics.DrawString((indx - 1).ToString(), font, fontbrush, p.X - w, p.Y - radius + 2, StringFormat)
                End If

            End If
            indx = indx + 1
        Next

        pen.Dispose()
        brush.Dispose()
    End Sub


    Private Sub tbMapWidth_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbMapWidth.Scroll
        Dim width As Double
        width = tbMapWidth.Value() / 4

        myViews(0).Height = width
        myViews(0).Width = width

        tt.SetToolTip(tbMapWidth, width)
    End Sub

    Private Sub tbMapWidth_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tbMapWidth.MouseUp
        refreshMap()
    End Sub

    Private Sub pbMap_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbMap.MouseDown

        Dim pc As New MPNet.PixelCoord()
        pc.X = e.X
        pc.Y = e.Y

        Dim points(0) As MPNet.PixelCoord
        points(0) = pc
        Try
            myViews(0).CenterPoint = myRenderService.ConvertToLatLong(points, myViews(0), _
                m_pixelWidth, m_pixelHeight)(0)
        Catch ex As Exception
            Debug.Write(ex.ToString)
        End Try

        refreshMap()

    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        refreshMap()
    End Sub


    'Pass in a String and have the first letter of each word capitalized
    'For instace 'MY STriNG' returns 'My String'
    Private Function ProperCase(ByVal instr As String) As String

        ProperCase = " " & LCase(instr)
        Dim posit As Integer
        Dim thisASCII As Integer

        For posit = 2 To Len(ProperCase)
            thisASCII = Asc(Mid(ProperCase, posit, 1))
            If ((Mid(ProperCase, posit - 1, 1) = " ")) Then
                ProperCase = Mid(ProperCase, 1, posit - 1) & UCase(Mid(ProperCase, posit, 1)) & _
                     Mid(ProperCase, posit + 1, Len(ProperCase))
            End If
        Next
        ProperCase = Trim(ProperCase)
    End Function

    'returns a nicely formatted 10 digit phone number
    Private Function formatPhone(ByVal phone As String) As String

        If Len(phone) = 10 Then
            formatPhone = "(" & Mid(phone, 1, 3) & ") " & Mid(phone, 4, 3) & "-" & Mid(phone, 7, 4)
        Else
            formatPhone = phone
        End If

    End Function

    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        doPOIQuery()
    End Sub

End Class
0
 
LVL 5

Expert Comment

by:maralans
ID: 17897495
I think this is for the mappoint web service:

Imports System
Imports System.Net
Imports DirectionsmagTutorial.MPNet

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public myFindService As New MPNet.FindServiceSoap()
    Public myRenderService As New MPNet.RenderServiceSoap()
    Public myRouteService As New RouteServiceSoap()

    Public myDataSourceName As String

    Dim PixelWidth As Integer
    Dim PixelHeight As Integer

    Public myViews(0) As MPNet.ViewByHeightWidth

    Public StopPins() As MPNet.Pushpin

    Dim NumberOfStops As Integer = 0
    Dim myRoute As Route

    Public CenterPoint As latLong

    Public foundAddressResults As FindResults


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtStreet As System.Windows.Forms.TextBox
    Friend WithEvents cmbCountry As System.Windows.Forms.ComboBox
    Friend WithEvents tbMapWidth As System.Windows.Forms.TrackBar
    Friend WithEvents pbMap As System.Windows.Forms.PictureBox
    Friend WithEvents btnAddStop As System.Windows.Forms.Button
    Friend WithEvents tt As System.Windows.Forms.ToolTip
    Friend WithEvents btnGetRoute As System.Windows.Forms.Button
    Friend WithEvents lstDirections As System.Windows.Forms.ListBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents sbStatus As System.Windows.Forms.StatusBar
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.btnGetRoute = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtStreet = New System.Windows.Forms.TextBox
        Me.btnAddStop = New System.Windows.Forms.Button
        Me.cmbCountry = New System.Windows.Forms.ComboBox
        Me.tbMapWidth = New System.Windows.Forms.TrackBar
        Me.pbMap = New System.Windows.Forms.PictureBox
        Me.tt = New System.Windows.Forms.ToolTip(Me.components)
        Me.lstDirections = New System.Windows.Forms.ListBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.sbStatus = New System.Windows.Forms.StatusBar
        Me.GroupBox1.SuspendLayout()
        CType(Me.tbMapWidth, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.pbMap, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.btnGetRoute)
        Me.GroupBox1.Controls.Add(Me.btnClear)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.txtStreet)
        Me.GroupBox1.Controls.Add(Me.btnAddStop)
        Me.GroupBox1.Controls.Add(Me.cmbCountry)
        Me.GroupBox1.Location = New System.Drawing.Point(10, 9)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(384, 268)
        Me.GroupBox1.TabIndex = 28
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Find an Address or Place"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(29, 37)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(336, 74)
        Me.Label3.TabIndex = 37
        Me.Label3.Text = "You can enter a street address such as One Microsoft Way, Redmond,WA or a place s" & _
            "uch as a zipcode or landmark"
        '
        'btnGetRoute
        '
        Me.btnGetRoute.Location = New System.Drawing.Point(240, 231)
        Me.btnGetRoute.Name = "btnGetRoute"
        Me.btnGetRoute.Size = New System.Drawing.Size(125, 27)
        Me.btnGetRoute.TabIndex = 36
        Me.btnGetRoute.Text = "Get Route"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(106, 231)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(124, 27)
        Me.btnClear.TabIndex = 35
        Me.btnClear.Text = "Clear all Stops"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(19, 120)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(67, 18)
        Me.Label2.TabIndex = 29
        Me.Label2.Text = "Country"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(19, 166)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(202, 19)
        Me.Label1.TabIndex = 27
        Me.Label1.Text = "Address or place"
        '
        'txtStreet
        '
        Me.txtStreet.Location = New System.Drawing.Point(19, 185)
        Me.txtStreet.Name = "txtStreet"
        Me.txtStreet.Size = New System.Drawing.Size(346, 22)
        Me.txtStreet.TabIndex = 22
        '
        'btnAddStop
        '
        Me.btnAddStop.Location = New System.Drawing.Point(10, 231)
        Me.btnAddStop.Name = "btnAddStop"
        Me.btnAddStop.Size = New System.Drawing.Size(76, 27)
        Me.btnAddStop.TabIndex = 26
        Me.btnAddStop.Text = "Add Stop"
        '
        'cmbCountry
        '
        Me.cmbCountry.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbCountry.Items.AddRange(New Object() {"Austria", "Belgium", "Canada", "Denmark", "France", "Germany", "Italy", "Luxembourg", "Netherlands", "Norway", "Spain", "Sweden", "Switzerland", "United Kingdom", "United States"})
        Me.cmbCountry.Location = New System.Drawing.Point(96, 120)
        Me.cmbCountry.Name = "cmbCountry"
        Me.cmbCountry.Size = New System.Drawing.Size(163, 24)
        Me.cmbCountry.TabIndex = 28
        '
        'tbMapWidth
        '
        Me.tbMapWidth.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.tbMapWidth.LargeChange = 16
        Me.tbMapWidth.Location = New System.Drawing.Point(646, 286)
        Me.tbMapWidth.Maximum = 400
        Me.tbMapWidth.Minimum = 1
        Me.tbMapWidth.Name = "tbMapWidth"
        Me.tbMapWidth.Orientation = System.Windows.Forms.Orientation.Vertical
        Me.tbMapWidth.Size = New System.Drawing.Size(56, 279)
        Me.tbMapWidth.SmallChange = 4
        Me.tbMapWidth.TabIndex = 31
        Me.tbMapWidth.TickFrequency = 10
        Me.tbMapWidth.TickStyle = System.Windows.Forms.TickStyle.TopLeft
        Me.tbMapWidth.Value = 2
        '
        'pbMap
        '
        Me.pbMap.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pbMap.BackColor = System.Drawing.SystemColors.ControlDark
        Me.pbMap.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pbMap.Location = New System.Drawing.Point(10, 286)
        Me.pbMap.Name = "pbMap"
        Me.pbMap.Size = New System.Drawing.Size(627, 279)
        Me.pbMap.TabIndex = 30
        Me.pbMap.TabStop = False
        '
        'lstDirections
        '
        Me.lstDirections.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lstDirections.ItemHeight = 16
        Me.lstDirections.Location = New System.Drawing.Point(413, 37)
        Me.lstDirections.Name = "lstDirections"
        Me.lstDirections.Size = New System.Drawing.Size(281, 212)
        Me.lstDirections.TabIndex = 32
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(413, 9)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(67, 19)
        Me.Label4.TabIndex = 38
        Me.Label4.Text = "Directions"
        '
        'sbStatus
        '
        Me.sbStatus.Location = New System.Drawing.Point(0, 570)
        Me.sbStatus.Name = "sbStatus"
        Me.sbStatus.Size = New System.Drawing.Size(704, 18)
        Me.sbStatus.TabIndex = 39
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
        Me.ClientSize = New System.Drawing.Size(704, 588)
        Me.Controls.Add(Me.sbStatus)
        Me.Controls.Add(Me.lstDirections)
        Me.Controls.Add(Me.tbMapWidth)
        Me.Controls.Add(Me.pbMap)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Label4)
        Me.Name = "Form1"
        Me.Text = "DirectionsMag.com MapPoint Application"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        CType(Me.tbMapWidth, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.pbMap, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myFindService.Credentials = New NetworkCredential("2330", "YUzRJ9Be")
        myRenderService.Credentials = New NetworkCredential("2330", "YUzRJ9Be")
        myRouteService.Credentials = New NetworkCredential("2330", "YUzRJ9Be")

        myRenderService.UserInfoRenderHeaderValue = New UserInfoRenderHeader()
        myRenderService.UserInfoRenderHeaderValue.DefaultDistanceUnit = DistanceUnit.Mile

    End Sub


    Private Sub btnAddStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStop.Click

        ' This routine will take whatever was entered in the search field, try to
        ' Geocode it as a street or place, and if a succesful search is performed,
        ' add the location as a stop on our driving route
        ' Input can be a full address, a City, a post code, landmark, airport code...

        'Initialize the centerpoint to null. If we find a good match, we'll set it
        CenterPoint = Nothing

        sbStatus.Text = "Searching for address or place..."

        'Based on the selected Country, select a MapPoint Datasource to search against
        If cmbCountry.Text = "Canada" Or cmbCountry.Text = "United States" Then
            myDataSourceName = "MapPoint.NA"
        Else
            myDataSourceName = "MapPoint.EU"
        End If

        Try
            'Start by trying the input as a Street Address. If we don't make a
            'hit, we'll then try the input as a place.

            'Populate a FindAddressSpecification with the search options
            Dim findAddressSpec As New FindAddressSpecification()
            findAddressSpec.InputAddress = New Address()
            findAddressSpec.InputAddress.FormattedAddress = txtStreet.Text
            findAddressSpec.InputAddress.CountryRegion = cmbCountry.Text
            findAddressSpec.DataSourceName = myDataSourceName

            'Try to find the address
            Try
                foundAddressResults = myFindService.FindAddress(findAddressSpec)
            Catch ex As System.Web.Services.Protocols.SoapException
                'An error occured during the search.
                foundAddressResults = Nothing
            End Try

            'Did we get any results?
            If (Not foundAddressResults Is Nothing) Then
                'If we have exactly one hit, use it as the centerpoint for this stop
                If foundAddressResults.NumberFound = 1 Then
                    sbStatus.Text = "Found one Candidate"
                    Dim fr As FindResult = foundAddressResults.Results(0)
                    CenterPoint = New LatLong()
                    CenterPoint = fr.FoundLocation.LatLong
                    myViews(0) = fr.FoundLocation.BestMapView.ByHeightWidth

                    txtStreet.Text = fr.FoundLocation.Address.FormattedAddress.ToString
                End If

                'If more than one candidate, show a dialog that allows the user to choose one
                If foundAddressResults.NumberFound > 1 Then
                    sbStatus.Text = "Found multiple candidates"
                    Dim frm As New CandidatePicker()
                    frm.ShowDialog(Me)
                End If
            End If

            'If searching as a street address didn't yield a hit, lets try a place find
            If CenterPoint Is Nothing Then
                Dim findSpec As New MPNet.FindSpecification()
                findSpec.InputPlace = txtStreet.Text
                findSpec.DataSourceName = myDataSourceName

                Dim foundResults As MPNet.FindResults
                foundResults = myFindService.Find(findSpec)

                'If a place was found, we'll use the first candidate as our stop.
                If Not foundResults Is Nothing And foundResults.NumberFound > 0 Then
                    Dim fr As FindResult = foundResults.Results(0)
                    CenterPoint = New LatLong()
                    CenterPoint = fr.FoundLocation.LatLong
                    myViews(0) = fr.FoundLocation.BestMapView.ByHeightWidth
                End If
            End If

            'If a succesful search was done, we'll have a CenterPoint. Add a new
            'Stop to our array of stops, and create a pushpin to mark the location on the map
            If Not CenterPoint Is Nothing Then
                Dim findPin As New Pushpin()
                NumberOfStops = NumberOfStops + 1

                findPin.Label = ""
                findPin.LatLong = CenterPoint
                findPin.IconDataSource = "MapPoint.Icons"
                findPin.IconName = "" & (304 + NumberOfStops)
                findPin.PinID = "pinid"

                ReDim Preserve StopPins(NumberOfStops - 1)
                StopPins(NumberOfStops - 1) = findPin

                sbStatus.Text = ""

                'Redraw the map showing the new stop marked with a pushpin
                refreshMap()
            Else
                sbStatus.Text = "No good matches were found."
            End If

        Catch ex As Exception
            'Something went wrong during the search
            sbStatus.Text = "An Error has occured."
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "An error has occured during address lookup.")
            Debug.WriteLine(ex.ToString)
        End Try

    End Sub

   

    Public Sub refreshMap()

        'This routine requests a new map from the MapPoint service, and displays it
        'in a picturebox on the main form

        sbStatus.Text = "Generating map..."
        Try
            Dim mapSpec As New MPNet.MapSpecification()
            mapSpec.DataSourceName = myDataSourceName

            'Request the map sized to fit in our picturebox
            PixelWidth = pbMap.Width
            PixelHeight = pbMap.Height
            mapSpec.Options = New MPNet.MapOptions()
            mapSpec.Options.Format = New MPNet.ImageFormat()
            mapSpec.Options.Format.Height = PixelHeight
            mapSpec.Options.Format.Width = PixelWidth

            'MapPoint .NET supports many MapStyles. We'll go with 'Road', but
            'have fun and experiment with some of the others, such as terrain
            mapSpec.Options.Style = MPNet.MapStyle.Road
            mapSpec.Options.FontSize = MapFontSize.Smaller

            mapSpec.Pushpins = StopPins
            mapSpec.Views = myViews
            mapSpec.Route = myRoute

            'Make the call to the MapPoint .NET service and display the resulting map in the picturebox
            Dim mapImages() As MPNet.MapImage
            mapImages = myRenderService.GetMap(mapSpec)
            pbMap.Image = New Bitmap(New System.IO.MemoryStream(mapImages(0).MimeData.Bits))
            sbStatus.Text = ""

        Catch ex As Exception
            'Something went wrong during the map request
            sbStatus.Text = "An Error has occured."
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "An error has occured during the map request.")
            Debug.WriteLine(ex.ToString)

        End Try

    End Sub

    Private Sub tbMapWidth_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbMapWidth.Scroll
        'The user is scrolling the Zoom in/out slider. Set the tooltip
        Dim width As Double
        width = tbMapWidth.Value() / 4

        myViews(0).Height = width
        myViews(0).Width = width

        tt.SetToolTip(tbMapWidth, width)
    End Sub

    Private Sub tbMapWidth_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tbMapWidth.MouseUp
        'The user has released the Zoom scroller. Refresh the map display
        refreshMap()
    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        'The main form has been resized. request a new map
        If Not myRenderService.Credentials Is Nothing Then
            refreshMap()
        End If

    End Sub

    Private Sub pbMap_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbMap.MouseDown

        'The user has clicked on the map to re-center it. Calculate the new centerpoint
        'By converting the location they clicked in pixels to a new latLong Coordinate
        Dim pc As New MPNet.PixelCoord()
        pc.X = e.X
        pc.Y = e.Y

        Dim points(0) As MPNet.PixelCoord
        points(0) = pc

        Try
            'Convert from pixels to LatLong
            myViews(0).CenterPoint = myRenderService.ConvertToLatLong(points, myViews(0), _
                PixelWidth, PixelHeight)(0)
        Catch ex As Exception
            Debug.Write(ex.ToString)
        End Try

        'And of course, make a call to request and display the newly centered map
        refreshMap()
    End Sub


    Private Sub btnGetRoute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRoute.Click

        sbStatus.Text = "Generating Driving Directions..."
        Try
            'Add each stop to a RouteSegmentSpec object
            Dim ThisStop As Integer
            Dim routeSegmentsSpec(NumberOfStops - 1) As SegmentSpecification
            For ThisStop = 0 To NumberOfStops - 1
                routeSegmentsSpec(ThisStop) = New SegmentSpecification()
                routeSegmentsSpec(ThisStop).Waypoint = New Waypoint()
                routeSegmentsSpec(ThisStop).Waypoint.Name = "Stop " & ThisStop
                routeSegmentsSpec(ThisStop).Waypoint.Location = New Location()
                routeSegmentsSpec(ThisStop).Waypoint.Location.LatLong = StopPins(ThisStop).LatLong
            Next

            Dim routeSpec As New RouteSpecification()
            routeSpec.DataSourceName = myDataSourceName
            routeSpec.Segments = routeSegmentsSpec

            'Request the route and directions from the MapPoint .NET service
            myRoute = myRouteService.CalculateRoute(routeSpec)

            'Loop through each segment, and each segment's directions
            'Put the text of each turn in a list box
            lstDirections.Items.Clear()

            Dim myDirection As Direction
            Dim thisSegment As Segment
            Dim segmentNumber As Integer = -1
            Dim locs(myRoute.Itinerary.Segments.Length - 1) As Location

            For Each thisSegment In myRoute.Itinerary.Segments
                segmentNumber = segmentNumber + 1
                locs(segmentNumber) = New MPNet.Location()
                locs(segmentNumber).LatLong = thisSegment.Waypoint.Location.LatLong

                For Each myDirection In thisSegment.Directions
                    lstDirections.Items.Add(myDirection.Instruction.ToString())
                Next
            Next

            'Get the BestMapView to show this route overview
            myViews(0) = myRenderService.GetBestMapView(locs, myDataSourceName).ByHeightWidth

            'Redraw the map to show the route highlighted
            refreshMap()

        Catch ex As Exception
            sbStatus.Text = "An Error has occured."
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "An error has occured during Route generation.")
        End Try
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'wipe out the existing stops and directions
        NumberOfStops = 0
        lstDirections.Items.Clear()
        myRoute = Nothing
        StopPins = Nothing

        'redraw the map without the route highlighted
        refreshMap()
    End Sub

    Private Sub lstDirections_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDirections.SelectedIndexChanged

        'Get the latLong coordinate that corresponds to the turn instruction
        'that was selected. Then redraw
        Dim indx As Integer = lstDirections.SelectedIndex
        Dim thisSegment As Segment

        For Each thisSegment In myRoute.Itinerary.Segments
            If indx < thisSegment.Directions.Length Then
                myViews(0).CenterPoint = thisSegment.Directions(indx).LatLong
                Exit For
            Else
                indx = indx - thisSegment.Directions.Length
            End If
        Next

        'myViews(0).CenterPoint = myRoute.Itinerary.Segments().Waypoint.Location.LatLong
        refreshMap()
    End Sub

 
   
End Class



Imports DirectionsmagTutorial.MPNet

Public Class CandidatePicker
    Inherits System.Windows.Forms.Form

    Dim frm1 As Form1

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnSelect As System.Windows.Forms.Button
    Friend WithEvents lbCandidates As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.btnSelect = New System.Windows.Forms.Button()
        Me.lbCandidates = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(328, 16)
        Me.Label1.TabIndex = 31
        Me.Label1.Text = "Select an Address Candidate from the list below."
        '
        'btnSelect
        '
        Me.btnSelect.Location = New System.Drawing.Point(120, 288)
        Me.btnSelect.Name = "btnSelect"
        Me.btnSelect.Size = New System.Drawing.Size(96, 32)
        Me.btnSelect.TabIndex = 30
        Me.btnSelect.Text = "OK"
        '
        'lbCandidates
        '
        Me.lbCandidates.Location = New System.Drawing.Point(8, 32)
        Me.lbCandidates.Name = "lbCandidates"
        Me.lbCandidates.Size = New System.Drawing.Size(336, 238)
        Me.lbCandidates.TabIndex = 29
        '
        'CandidatePicker
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(360, 324)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.btnSelect, Me.lbCandidates})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "CandidatePicker"
        Me.Text = "CandidatePicker"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub CandidatePicker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        frm1 = Form1.ActiveForm

        Try

            Dim fr As FindResult
            Dim strItem As String
            Dim cnt As Integer = 1
            For Each fr In frm1.foundAddressResults.Results

                strItem = cnt & "] " & fr.FoundLocation.Address.AddressLine & ", " & fr.FoundLocation.Address.PrimaryCity & _
                          ", " + fr.FoundLocation.Address.Subdivision & " " & fr.FoundLocation.Address.PostalCode & _
                          " [" & fr.Score & "]"

                lbCandidates.Items.Add(strItem)
                cnt = cnt + 1
            Next
        Catch ex As Exception
            Debug.Write(ex.ToString)

        End Try

    End Sub

    Private Sub lbCandidates_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbCandidates.SelectedIndexChanged

        Dim indx As Integer
        indx = lbCandidates.SelectedIndex()

        frm1.CenterPoint = New LatLong()
        frm1.CenterPoint = frm1.foundAddressResults.Results(indx).FoundLocation.LatLong

        frm1.myViews(0) = frm1.foundAddressResults.Results(indx).FoundLocation.BestMapView.ByHeightWidth

        frm1.txtStreet.Text = frm1.foundAddressResults.Results(indx).FoundLocation.Address.FormattedAddress.ToString

        frm1.refreshMap()
    End Sub

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click

        CandidatePicker.ActiveForm.Close()
    End Sub

End Class

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:maralans
ID: 17897507
This is a working demo:

Public Class MapPointDemoFrm
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Button7 As System.Windows.Forms.Button
    Friend WithEvents Button8 As System.Windows.Forms.Button
    Friend WithEvents Button9 As System.Windows.Forms.Button
    Friend WithEvents Button10 As System.Windows.Forms.Button
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.Button4 = New System.Windows.Forms.Button()
        Me.Button5 = New System.Windows.Forms.Button()
        Me.Button6 = New System.Windows.Forms.Button()
        Me.Button7 = New System.Windows.Forms.Button()
        Me.Button8 = New System.Windows.Forms.Button()
        Me.Button9 = New System.Windows.Forms.Button()
        Me.Button10 = New System.Windows.Forms.Button()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(0, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(208, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "First Location"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(0, 40)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(208, 24)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "Target Restaurants"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(0, 72)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(208, 24)
        Me.Button3.TabIndex = 2
        Me.Button3.Text = "Next Location"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(0, 104)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(208, 24)
        Me.Button4.TabIndex = 3
        Me.Button4.Text = "Wire Location 1 to Location 2"
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(0, 136)
        Me.Button5.Name = "Button5"
        Me.Button5.Size = New System.Drawing.Size(208, 24)
        Me.Button5.TabIndex = 4
        Me.Button5.Text = "Extend Line to Latitude-Longitude"
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(0, 168)
        Me.Button6.Name = "Button6"
        Me.Button6.Size = New System.Drawing.Size(208, 24)
        Me.Button6.TabIndex = 5
        Me.Button6.Text = "Get the Route"
        '
        'Button7
        '
        Me.Button7.Location = New System.Drawing.Point(0, 200)
        Me.Button7.Name = "Button7"
        Me.Button7.Size = New System.Drawing.Size(208, 24)
        Me.Button7.TabIndex = 6
        Me.Button7.Text = "Hide the Itinerary"
        '
        'Button8
        '
        Me.Button8.Location = New System.Drawing.Point(0, 232)
        Me.Button8.Name = "Button8"
        Me.Button8.Size = New System.Drawing.Size(208, 24)
        Me.Button8.TabIndex = 7
        Me.Button8.Text = "Map Custom Assets"
        '
        'Button9
        '
        Me.Button9.Location = New System.Drawing.Point(0, 264)
        Me.Button9.Name = "Button9"
        Me.Button9.Size = New System.Drawing.Size(208, 24)
        Me.Button9.TabIndex = 8
        Me.Button9.Text = "Map Sales Data"
        '
        'Button10
        '
        Me.Button10.Location = New System.Drawing.Point(0, 296)
        Me.Button10.Name = "Button10"
        Me.Button10.Size = New System.Drawing.Size(208, 24)
        Me.Button10.TabIndex = 9
        Me.Button10.Text = "Quit"
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(0, 352)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(200, 225)
        Me.ListBox1.TabIndex = 10
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 328)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(192, 24)
        Me.Label1.TabIndex = 11
        '
        'MapPointDemoFrm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(208, 581)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.ListBox1, Me.Button10, Me.Button9, Me.Button8, Me.Button7, Me.Button6, Me.Button5, Me.Button4, Me.Button3, Me.Button2, Me.Button1})
        Me.Location = New System.Drawing.Point(875, 10)
        Me.Name = "MapPointDemoFrm"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "MapPoint Demo"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim oApp As MapPoint.Application
    Dim WithEvents oMap As MapPoint.Map   ' With Events!
    Dim oDataMap As MapPoint.DataMap
    Dim oWaypoint1 As MapPoint.Waypoint
    Dim oWaypoint2 As MapPoint.Waypoint
    Dim oRoute As MapPoint.Route
    Dim oFindResults As MapPoint.FindResults
    Dim oLocation1 As MapPoint.Location
    Dim oLocation2 As MapPoint.Location
    Dim oLocation3 As MapPoint.Location
    Dim oPushPin1 As MapPoint.Pushpin
    Dim oPushPin2 As MapPoint.Pushpin
    Dim oPushPin3 As MapPoint.Pushpin
    Dim MapPath As String
    Dim sMePath As String
    Dim oShape1 As MapPoint.Shape
    Dim oShape2 As MapPoint.Shape
    Dim oSymbols As MapPoint.Symbols
    Dim oSymbol1 As MapPoint.Symbol
    Dim oSymbol2 As MapPoint.Symbol
    Dim dsGrid As MapPoint.DataSet
    Dim dsRs As MapPoint.Recordset
    Dim aGrid(,) As Object   ' VB.NET requires you to declare dimension count - hence, 2 dimensions

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
        MapPath = "C:\MapPoint2002Demo\Templates\New North American Map.ptt"    ' Customize for your system"
        oApp = CreateObject("Mappoint.Application")
        oApp.Visible = True
        oApp.WindowState = MapPoint.GeoWindowState.geoWindowStateNormal
        oMap = oApp.NewMap(MapPath)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Map the First Location - a bus-stop at 3rd and Pine, in Seattle, WA

        ' Initialize objects of the form
        ListBox1.Items.Clear()
        Label1.Text = ""
        Label1.Refresh()
        ListBox1.Refresh()
        Button2.Enabled = True

        ' Initialize the MapStyle in case you Mapped Sales by county before clicking here
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad
        oFindResults = oMap.FindAddressResults("3rd Ave & Pine St", "Seattle", , "Wa", 98101, MapPoint.GeoCountry.geoCountryUnitedStates)      '.Item(1)
        oLocation1 = oFindResults(1)
        oLocation1.GoTo()
        oPushPin1 = oMap.AddPushpin(AtLocation:=oLocation1, Name:="Downtown Seattle")
        oPushPin1.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon
        Button1.Enabled = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' Show the Chinese, Steak and Seafood restaurants within 0.2 miles of the bus-stop
        ListBox1.Items.Clear()
        Label1.Text = ""
        Label1.Refresh()
        ListBox1.Refresh()
        oPushPin1.Symbol = 180                      ' Standard Bus Symbol
        oPushPin1.Note = "Bus Stop"
        oPushPin1.BalloonState = MapPoint.GeoBalloonState.geoDisplayName
        oLocation1.FindNearby(Distance:=0.2)
        oMap.PlaceCategories.Visible = MapPoint.GeoTriState.geoFalse ' Hide them all at first
        Dim i As Integer
        ListBox1.Items.Add("Built-in Place Categories") ' Title for the list to be inserted
        For i = 1 To oMap.PlaceCategories.Count
            ListBox1.Items.Add("    " & oMap.PlaceCategories(i).Name)  ' Show list of built-in place categories
            If oMap.PlaceCategories(i).Name = "Restaurants - Chinese" _
                Or oMap.PlaceCategories(i).Name = "Restaurants - Steak" _
                Or oMap.PlaceCategories(i).Name = "Restaurants - Seafood" Then
                oMap.PlaceCategories(i).Visible = True  ' Show just these three categories
            End If
        Next i
        oFindResults = oLocation1.FindNearby(Distance:=0.2)   ' Count the visible ones
        Label1.Text = "Count of target restaurants is " & oFindResults.Count - 1  ' omit the busstop
        Label1.Show()
        Button2.Enabled = False
        Button3.Enabled = True
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ' Locate a picturesque waterfront location in Kirkland, WA
        Label1.Text = ""
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad

        oPushPin1.BalloonState = MapPoint.GeoBalloonState.geoDisplayName
        oFindResults = oMap.FindAddressResults("Central Way & Lake Ave W", "Kirkland", , "Wa", 98033, MapPoint.GeoCountry.geoCountryUnitedStates)      '.Item(1)
        oLocation2 = oFindResults(1)
        oLocation2.GoTo()
        oPushPin2 = oMap.AddPushpin(AtLocation:=oLocation2, Name:="Favorite Corner")
        oPushPin2.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon
        Button4.Enabled = True
        Button3.Enabled = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ' Stretch a transmission line from Kirkland to the Bus-Stop at 3rd and Pine in downtown Seattle
        '  Use a custom pushpin icon for Transmission towers.
        Label1.Text = ""
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad
        oMap.Altitude = 25
        oSymbols = oMap.Symbols

        If oSymbols.Count <= 256 Then  ' Don't create these more than once.
            oSymbol1 = oSymbols.Add(sMePath & "\Samples\TransmissionTower.bmp")
            oSymbol1.Name = "TransmissionTower"
            oSymbol2 = oSymbols.Add(sMePath & "\Samples\SubStation.bmp")
            oSymbol2.Name = "SubStation"
        End If

        oPushPin2.BalloonState = MapPoint.GeoBalloonState.geoDisplayNone
        oShape1 = oMap.Shapes.AddLine(BeginLocation:=oLocation1, EndLocation:=oLocation2)
        oShape1.Line.Weight = 1                     ' Pixel
        oShape1.Line.ForeColor = RGB(255, 64, 0)
        'oPushPin1.Symbol = oSymbol1.ID              ' Custom Symbol for Transmission Tower
        ' oPushPin1.Name = "Grid Start"
        'oPushPin2.Symbol = oSymbol1.ID
        Button5.Enabled = True
        Button4.Enabled = False
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        'Extend the Line to a Latitude-Longitude location in Redmond, WA. Use another custom
        '  pushpin icon for "Substation"
        Label1.Text = ""
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad
        oLocation3 = oMap.GetLocation(47.63862, -122.13107, 500)
        oPushPin3 = oMap.AddPushpin(AtLocation:=oLocation3, Name:="Substation 345")
        oPushPin3.BalloonState = MapPoint.GeoBalloonState.geoDisplayName
        'oPushPin3.Symbol = oSymbol2.ID              ' Custom Symbol for Substation
        oShape2 = oMap.Shapes.AddLine(BeginLocation:=oLocation2, EndLocation:=oLocation3)
        oShape2.Line.Weight = 1
        oShape2.Line.ForeColor = RGB(255, 64, 0)
        oPushPin3.Highlight = True
        oMap.Altitude = 30
        Button6.Enabled = True
        Button5.Enabled = False
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        ' Map a driving route and itinerary from Seattle to Redmond.
        Label1.Text = ""
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad
        oRoute = oMap.ActiveRoute
        oWaypoint1 = oRoute.Waypoints.Add(Anchor:=oLocation1)
        oWaypoint2 = oRoute.Waypoints.Add(Anchor:=oLocation3)
        oRoute.Calculate()
        Button7.Enabled = True
        Button6.Enabled = False
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        ' Remove the Itinerary from the screen
        Label1.Text = ""
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad
        oApp.ItineraryVisible = False
        Button8.Enabled = True
        Button7.Enabled = False
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        ' Map a distribution network from our own records (an Excel worksheet)
        Label1.Text = ""
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleRoad
        oSymbols = oMap.Symbols
        oSymbol1 = oSymbols.Add(sMePath & "\Samples\TransmissionTower.bmp")
        oSymbol1.Name = "Trans.Tower"
        oSymbol2 = oSymbols.Add(sMePath & "\Samples\SubStation.bmp")
        oSymbol2.Name = "SubStn"
        Dim MKGrid As String
        MKGrid = sMePath & "\Samples\Grid.xls!Sheet1!A1:E100" ' More rows than needed
        ReDim aGrid(4, 1)  'Values are UBounds, not element count
        aGrid(0, 0) = "ID"
        aGrid(0, 1) = MapPoint.GeoFieldType.geoFieldData
        aGrid(1, 0) = "Structure Name"
        aGrid(1, 1) = MapPoint.GeoFieldType.geoFieldName
        aGrid(2, 0) = "Type"
        aGrid(2, 1) = MapPoint.GeoFieldType.geoFieldData
        aGrid(3, 0) = "Latitude"
        aGrid(3, 1) = MapPoint.GeoFieldType.geoFieldLatitude
        aGrid(4, 0) = "Longitude"
        aGrid(4, 1) = MapPoint.GeoFieldType.geoFieldLongitude
        dsGrid = oMap.DataSets.ImportData(DataSourceMoniker:=MKGrid, ImportFlags:=MapPoint.GeoImportFlags.geoImportExcelA1 Or MapPoint.GeoImportFlags.geoImportFirstRowIsHeadings, ArrayOfFields:=aGrid)
        dsGrid.ZoomTo()
        Dim iRecordCount As Integer
        iRecordCount = dsGrid.RecordCount
        Dim PinArray(,) As Object
        ReDim PinArray(dsGrid.RecordCount - 1, 4) ' UBound =(records in the dataset-1)

        Dim iElement As Integer                ' Index to rows in PinArray

        dsRs = dsGrid.QueryAllRecords          ' Build a recordset so we can look at the records of the dataset
        dsRs.MoveFirst()

        Do While Not dsRs.EOF                  ' Sequence of records in dsRs is arbitrary, so resequence by ID
            iElement = dsRs.Fields(1).Value                 'id of record in dsRs
            PinArray(iElement - 1, 0) = iElement              'Save in array as id
            PinArray(iElement - 1, 1) = dsRs.Fields(2).Value  'Structure Name
            PinArray(iElement - 1, 2) = dsRs.Fields(3).Value  'Type
            PinArray(iElement - 1, 3) = dsRs.Fields(4).Value  'Latitude
            PinArray(iElement - 1, 4) = dsRs.Fields(5).Value  'Longitude
            dsRs.MoveNext()
        Loop
        dsGrid.Delete()                               ' Remove its pushpins from the map
        Dim i As Integer
        For i = 1 To iRecordCount - 1                 ' Move through records in original order
            oLocation2 = oMap.GetLocation(PinArray(i - 1, 3), PinArray(i - 1, 4))
            oLocation3 = oMap.GetLocation(PinArray(i, 3), PinArray(i, 4))
            If PinArray(i - 1, 2) = 1 Then
                oPushPin2 = oMap.AddPushpin(AtLocation:=oLocation2, Name:=PinArray(i - 1, 1))
                oPushPin2.Symbol = oSymbol2.ID
                oPushPin2.Highlight = True
            Else
                oPushPin2 = oMap.AddPushpin(AtLocation:=oLocation2, Name:=PinArray(i - 1, 1))
                oPushPin2.Symbol = oSymbol1.ID
            End If
            oShape2 = oMap.Shapes.AddLine(BeginLocation:=oLocation2, EndLocation:=oLocation3)
            oShape2.Line.Weight = 1
            oShape2.Line.ForeColor = RGB(255, 64, 0)
        Next i
        If PinArray(i - 1, 2) = 1 Then
            oPushPin3 = oMap.AddPushpin(AtLocation:=oLocation3, Name:=PinArray(i - 1, 1))
            oPushPin3.Symbol = oSymbol2.ID         ' Substation custom pushpin
            oPushPin3.Highlight = True
        Else
            oPushPin3 = oMap.AddPushpin(AtLocation:=oLocation3, Name:=PinArray(i - 1, 1))
            oPushPin3.Symbol = oSymbol1.ID         ' Transmission Tower custom pushpin
        End If
        Button9.Enabled = True
        Button8.Enabled = False
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        ' Map Sales data for counties in Massachusetts, showing sized circles.
        ListBox1.Items.Clear()
        Label1.Text = ""
        Label1.Refresh()
        ListBox1.Refresh()
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
        Button7.Enabled = False
        Button8.Enabled = False
        oMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleData
        Dim oField As MapPoint.Field
        dsGrid = oApp.ActiveMap.DataSets.ImportData(DataSourceMoniker:="C:\MapPointDemo\Samples\SampData.xls!Massachusetts Sales!A1:H15")
        dsGrid.ZoomTo()
        oField = dsGrid.Fields("2000 ($)")          ' Chosen column of worksheet
        oDataMap = _
            dsGrid.DisplayDataMap(DataMapType:=MapPoint.GeoDataMapType.geoDataMapTypeSizedCircle, _
            DataField:=oField, _
            ShowDataBy:=MapPoint.GeoShowDataBy.geoShowByDefault, _
            DataRangeCount:=5, _
            DataRangeType:=MapPoint.GeoDataRangeType.geoRangeTypeDiscreteEqualRanges, _
            DataRangeOrder:=MapPoint.GeoDataRangeOrder.geoRangeOrderDefault, _
            ColorScheme:=MapPoint.GeoDataConstants.geoColorSchemeDefault)
        oDataMap.LegendTitle = "Sales By County - Year 2000"
        Button9.Enabled = False
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Form_Unload(0)
        Me.Close()
    End Sub

    Private Sub Form_Unload(ByVal Cancel As Integer)
        If Not (oMap Is Nothing) Then
            oMap.Saved = True  ' Forestall the "Save Changes?" dialog
            oMap = Nothing
            CType(oApp, MapPoint._Application).Quit() ' Cast to base type.
            '  Resolves ambiguity between Application.Quit() and Application_Events.Quit()
            oApp = Nothing
        End If
    End Sub

    Private Sub oMap_SelectionChange(ByVal NewSelection As Object, ByVal OldSelection As Object) Handles oMap.SelectionChange
        Label1.Text = "Handling An Event!"
        ListBox1.Items.Clear()
        Label1.Refresh()
        ListBox1.Refresh()
        If TypeName(NewSelection) = "Pushpin" Then
            oPushPin1 = NewSelection
            ListBox1.Items.Add("You selected " & oPushPin1.Name)
            oPushPin1 = Nothing
        ElseIf TypeName(NewSelection) = "Shape" Then
            ListBox1.Items.Add("Shape")
        Else
            ListBox1.Items.Add("You selected a " & TypeName(NewSelection))
        End If
        ListBox1.Items.Add("Old Selection is a " & TypeName(OldSelection))
    End Sub

End Class
0
 
LVL 5

Expert Comment

by:maralans
ID: 17897517
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

//Add MapPoint namespace
using MapPoint;

namespace MP2KSample
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Button button1;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(10, 46);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(403, 28);
            this.button1.TabIndex = 0;
            this.button1.Text = "Find";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
            this.ClientSize = new System.Drawing.Size(532, 302);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  System.Windows.Forms.Application.Run(new Form1());
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  //Define an application instance
                  ApplicationClass app = null;

                  //Define a location instance
                  Location location = null;

                  //Define a FindResults instance
                  FindResults frs = null;

                  try

                  {
                        //Create an application class
                        app = new ApplicationClass();

                        //Now get the location
                        frs = app.ActiveMap.FindAddressResults("1 Microsoft Way", "Redmond", string.Empty, "WA", "", null);

                        //Check if the find query is succesfull
                        if(frs != null && frs.Count > 0)

                        {
                              object index = 1;

                              location = frs.get_Item(ref index) as Location;

                              //Male the MapPoint 2004 application visible
                              //and go to that location
                              app.Visible = true;
                              location.GoTo();

                              //Do your processing with the location
                              MessageBox.Show(location.StreetAddress.Value);

                        }
                  }
                  catch(Exception ex)
                  {
                        string message = ex.Message;
                  }
                  finally
                  {
                        if(app != null)
                        {
                              try
                              {
                                    app.Quit();
                              }
                              catch
                              {
                                    //This means your app has already quit!
                              }
                              finally
                              {
                                    app = null;
                              }
                        }
                  }
            }
      }
}
0
 
LVL 5

Expert Comment

by:maralans
ID: 17900175
0
 
LVL 5

Expert Comment

by:maralans
ID: 17900268
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now