-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
137 lines (105 loc) · 5.04 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraMap
Namespace GetSearchLocationAdditionalInfo
Partial Public Class Form1
Inherits Form
Private Const yourBingKey As String = "Your Bing Key"
Private map As MapControl
Private searchProvider As BingSearchDataProvider
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
PrepareMap()
AddHandler searchProvider.SearchCompleted, AddressOf searchDataProvider_SearchCompleted
End Sub
Private Sub search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles search.Click
idx = 0
asyncResult = Me.BeginInvoke(CType(AddressOf SearchAsync, DoSearch))
End Sub
Private Delegate Sub DoSearch()
Private asyncResult As IAsyncResult
Private idx As Integer = 0
Private addresses As New List(Of String) From {"505 N. Brand Blvd, Glendale CA 91203, USA", "1111 N Brand Blvd, Glendale, CA 91202, USA", "300 N Brand Blvd, Glendale, CA 91203, USA"}
Private Sub SearchAsync()
Me.EndInvoke(asyncResult)
If idx < addresses.Count Then
searchProvider.Search(addresses(idx))
idx += 1
End If
End Sub
Private Sub searchDataProvider_SearchCompleted(ByVal sender As Object, ByVal e As BingSearchCompletedEventArgs)
Dim result As SearchRequestResult = e.RequestResult
If result.ResultCode = RequestResultCode.Success Then
Dim regions As List(Of LocationInformation) = result.SearchResults
For Each region_Renamed As LocationInformation In regions
AddPushpin(region_Renamed.Location)
If idx = addresses.Count Then
map.ZoomToFitLayerItems()
End If
Next region_Renamed
DisplayResults(e.RequestResult)
asyncResult = Me.BeginInvoke(CType(AddressOf SearchAsync, DoSearch))
End If
If result.ResultCode = RequestResultCode.BadRequest Then
tbResults.Text &= "The Bing Search service does not work for this location."
End If
End Sub
Private Sub AddPushpin(ByVal geoPoint As GeoPoint)
Dim pin As New MapPushpin()
pin.Location = geoPoint
Dim layer As VectorItemsLayer = CType(Me.map.Layers(2), VectorItemsLayer)
CType(layer.Data, MapItemStorage).Items.Add(pin)
End Sub
Private Sub NavigateTo(ByVal geoPoint As GeoPoint)
map.CenterPoint = geoPoint
map.ZoomLevel = 15
End Sub
Private Sub DisplayResults(ByVal requestResult As SearchRequestResult)
Dim resultList As New StringBuilder("")
If requestResult.ResultCode = RequestResultCode.Success Then
Dim resCounter As Integer = 1
For Each resultInfo As LocationInformation In requestResult.SearchResults
resultList.Append(String.Format(vbLf & " Result {0}: " & vbLf, resCounter))
resultList.Append(String.Format(resultInfo.DisplayName & vbLf))
resultList.Append(String.Format("Geographical coordinates: {0}", resultInfo.Location))
resultList.Append(String.Format(vbLf & "______________________________" & vbLf))
resCounter += 1
Next resultInfo
End If
tbResults.Text &= resultList.ToString()
End Sub
Private Sub PrepareMap()
' Create a map control.
map = New MapControl()
' Specify the map position on the form.
map.Dock = DockStyle.Fill
' Add the map control to the window.
Me.Controls.Add(map)
' Bring the map to the front.
map.BringToFront()
' Create an image tiles layer and add it to the map.
Dim tilesLayer As New ImageLayer()
map.Layers.Add(tilesLayer)
' Create an information layer and add it to the map.
Dim infoLayer As New InformationLayer()
map.Layers.Add(infoLayer)
Dim items As New VectorItemsLayer()
items.Data = New MapItemStorage()
map.Layers.Add(items)
' Create a Bing data provider and specify the Bing key.
Dim bingProvider As New BingMapDataProvider()
tilesLayer.DataProvider = bingProvider
bingProvider.BingKey = yourBingKey
' Create a Bing search data provider and specify the Bing key.
searchProvider = New BingSearchDataProvider()
infoLayer.DataProvider = searchProvider
searchProvider.GenerateLayerItems = False
searchProvider.BingKey = yourBingKey
map.ShowSearchPanel = False
End Sub
End Class
End Namespace