Files
RecordOrganizer/app/DD-Record-Organiser/frmGoogle.vb
SchreiberM 3e6f1c8db8 MS
2016-11-16 09:43:16 +01:00

79 lines
2.3 KiB
VB.net

Imports System.Web
Imports System.Text
Imports DevExpress.XtraMap
Public Class frmGoogle
Private ReadOnly Property SearchLayer() As InformationLayer
Get
Return CType(MapControl1.Layers("SearchLayer"), InformationLayer)
End Get
End Property
Private ReadOnly Property SearchProvider() As BingSearchDataProvider
Get
Return CType(SearchLayer.DataProvider, BingSearchDataProvider)
End Get
End Property
Private Sub SearchLayer_DataRequestCompleted(ByVal sender As Object, ByVal e As RequestCompletedEventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Get the Google maps URL with defult zoom.
Dim url = GoogleMapUrl(txtAdress.Text, cmbType.Text, 0)
' Display the URL in the WebBrowser control.
WebBrowser1.Navigate(url)
SearchProvider.Search(txtAdress.Text)
MapControl1.ZoomToFitLayerItems()
End Sub
Private Function GoogleMapUrl(query As String, map_type As String, zoom As Integer)
' Start with the base map URL.
Dim _url As String = "http://maps.google.com/maps?"
' Add the query.
_url &= "q=" + HttpUtility.UrlEncode(query, Encoding.UTF8)
'Add the type.
map_type = GoogleMapTypeCode(map_type)
If Not IsNothing(map_type) Then
_url += "&t=" + map_type
End If
'Add the zoom level.
If (zoom > 0) Then
_url += "&z=" + zoom.ToString()
End If
Return _url
End Function
' Return a Google map type code.
Private Function GoogleMapTypeCode(map_type As String)
' Insert the proper type.
Select Case map_type
Case "Map"
Return "m"
Case "Satellite"
Return "k"
Case "Hybrid"
Return "h"
Case "Terrain"
Return "p"
Case "Google Earth"
Return "e"
Case Else
Return Nothing
End Select
End Function
Private Sub frmGoogle_Load(sender As Object, e As EventArgs) Handles Me.Load
InitializeComponent()
' AddHandler SearchLayer.DataRequestCompleted, AddressOf SearchLayer_DataRequestCompleted
End Sub
End Class