title: vb google maps specific location
body: <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>Imports System.Windows.Threading
  Imports System.Threading
  Imports System.Net
  Imports System.Drawing
  Imports System.IO
  Imports Microsoft.Win32
  
  Class Window1
  
  #Region "Fields"
      Private geoDoc As XDocument
      Private location As String
      Private zoom As Integer
      Private saveDialog As New SaveFileDialog
      Private mapType As String
      Private lat As Double
      Private lng As Double
  #End Region
  
      Private Sub GetGeocodeData()
          Dim geocodeURL As String = "http://maps.googleapis.com/maps/api/" &amp; _
                                  "geocode/xml?address=" &amp; location &amp; "&amp;sensor=false"
          Try
              geoDoc = XDocument.Load(geocodeURL)
          Catch ex As WebException
              Me.Dispatcher.BeginInvoke(New ThreadStart(AddressOf HideProgressBar), _
                                        DispatcherPriority.Normal, Nothing)
              MessageBox.Show("Ensure that internet connection is available.", _
                              "Map App", MessageBoxButton.OK, MessageBoxImage.Error)
              Exit Sub
          End Try
  
          Me.Dispatcher.BeginInvoke(New ThreadStart(AddressOf ShowGeocodeData), _
                                    DispatcherPriority.Normal, Nothing)
      End Sub
  
      Private Sub ShowGeocodeData()
          Dim responseStatus = geoDoc...&lt;status&gt;.Single.Value()
          If (responseStatus = "OK") Then
              Dim formattedAddress = geoDoc...&lt;formatted_address&gt;(0).Value()
              Dim latitude = geoDoc...&lt;location&gt;(0).Element("lat").Value()
              Dim longitude = geoDoc...&lt;location&gt;(0).Element("lng").Value()
              Dim locationType = geoDoc...&lt;location_type&gt;(0).Value()
  
              AddressTxtBlck.Text = formattedAddress
              LatitudeTxtBlck.Text = latitude
              LongitudeTxtBlck.Text = longitude
  
              Select Case locationType
                  Case "APPROXIMATE"
                      AccuracyTxtBlck.Text = "Approximate"
                  Case "ROOFTOP"
                      AccuracyTxtBlck.Text = "Precise"
                  Case Else
                      AccuracyTxtBlck.Text = "Approximate"
              End Select
  
              lat = Double.Parse(latitude)
              lng = Double.Parse(longitude)
  
              If (SaveButton.IsEnabled = False) Then
                  SaveButton.IsEnabled = True
                  RoadmapToggleButton.IsEnabled = True
                  TerrainToggleButton.IsEnabled = True
              End If
  
          ElseIf (responseStatus = "ZERO_RESULTS") Then
              MessageBox.Show("Unable to show results for: " &amp; vbCrLf &amp; _
                              location, "Unknown Location", MessageBoxButton.OK, _
                              MessageBoxImage.Information)
              DisplayXXXXXXs()
              AddressTxtBox.SelectAll()
          End If
          ShowMapButton.IsEnabled = True
          ZoomInButton.IsEnabled = True
          ZoomOutButton.IsEnabled = True
          MapProgressBar.Visibility = Windows.Visibility.Hidden
      End Sub
  
      ' Get and display map image in Image ctrl.
      Private Sub ShowMapImage()
          Dim bmpImage As New BitmapImage()
          Dim mapURL As String = "http://maps.googleapis.com/maps/api/staticmap?" &amp; _
                      "size=500x400&amp;markers=size:mid%7Ccolor:red%7C" &amp; _
                      location &amp; "&amp;zoom=" &amp; zoom &amp; "&amp;maptype=" &amp; mapType &amp; "&amp;sensor=false"
  
          bmpImage.BeginInit()
          bmpImage.UriSource = New Uri(mapURL)
          bmpImage.EndInit()
  
          MapImage.Source = bmpImage
      End Sub
  
      Private Sub ShowMapUsingLatLng()
          Dim bmpImage As New BitmapImage()
          Dim mapURL As String = "http://maps.googleapis.com/maps/api/staticmap?" &amp; _
                      "center=" &amp; lat &amp; "," &amp; lng &amp; "&amp;" &amp; _
                      "size=500x400&amp;markers=size:mid%7Ccolor:red%7C" &amp; _
                      location &amp; "&amp;zoom=" &amp; zoom &amp; "&amp;maptype=" &amp; mapType &amp; "&amp;sensor=false"
          bmpImage.BeginInit()
          bmpImage.UriSource = New Uri(mapURL)
          bmpImage.EndInit()
  
          MapImage.Source = bmpImage
      End Sub
  
      ' Zoom-in on map.
      Private Sub ZoomIn()
          If (zoom &lt; 21) Then
              zoom += 1
              ShowMapUsingLatLng()
  
              If (ZoomOutButton.IsEnabled = False) Then
                  ZoomOutButton.IsEnabled = True
              End If
          Else
              ZoomInButton.IsEnabled = False
          End If
      End Sub
  
      ' Zoom-out on map.
      Private Sub ZoomOut()
          If (zoom &gt; 0) Then
              zoom -= 1
              ShowMapUsingLatLng()
  
              If (ZoomInButton.IsEnabled = False) Then
                  ZoomInButton.IsEnabled = True
              End If
          Else
              ZoomOutButton.IsEnabled = False
          End If
      End Sub
  
      Private Sub SaveMap()
          Dim mapURL As String = "http://maps.googleapis.com/maps/api/staticmap?" &amp; _
                      "center=" &amp; lat &amp; "," &amp; lng &amp; "&amp;" &amp; _
                      "size=500x400&amp;markers=size:mid%7Ccolor:red%7C" &amp; _
                      location &amp; "&amp;zoom=" &amp; zoom &amp; "&amp;maptype=" &amp; mapType &amp; "&amp;sensor=false"
          Dim webClient As New WebClient()
          Try
              Dim imageBytes() As Byte = webClient.DownloadData(mapURL)
              Using ms As New MemoryStream(imageBytes)
                  Image.FromStream(ms).Save(saveDialog.FileName, Imaging.ImageFormat.Png)
              End Using
          Catch ex As WebException
              MessageBox.Show("Unable to save map. Ensure that you are" &amp; _
                              " connected to the internet.", "Error!", _
                              MessageBoxButton.OK, MessageBoxImage.Stop)
              Exit Sub
          End Try
      End Sub
  
      Private Sub MoveUp()
          ' Default zoom is 15 and at this level changing
          ' the center point is done by 0.003 degrees. 
          ' Shifting the center point is done by higher values
          ' at zoom levels less than 15.
          Dim diff As Double
          Dim shift As Double
          ' Use 88 to avoid values beyond 90 degrees of lat.
          If (lat &lt; 88) Then
              If (zoom = 15) Then
                  lat += 0.003
              ElseIf (zoom &gt; 15) Then
                  diff = zoom - 15
                  shift = ((15 - diff) * 0.003) / 15
                  lat += shift
              Else
                  diff = 15 - zoom
                  shift = ((15 + diff) * 0.003) / 15
                  lat += shift
              End If
              ShowMapUsingLatLng()
          Else
              lat = 90
          End If
      End Sub
  
      Private Sub MoveDown()
          Dim diff As Double
          Dim shift As Double
          If (lat &gt; -88) Then
              If (zoom = 15) Then
                  lat -= 0.003
              ElseIf (zoom &gt; 15) Then
                  diff = zoom - 15
                  shift = ((15 - diff) * 0.003) / 15
                  lat -= shift
              Else
                  diff = 15 - zoom
                  shift = ((15 + diff) * 0.003) / 15
                  lat -= shift
              End If
              ShowMapUsingLatLng()
          Else
              lat = -90
          End If
      End Sub
  
      Private Sub MoveLeft()
          Dim diff As Double
          Dim shift As Double
          ' Use -178 to avoid negative values below -180.
          If (lng &gt; -178) Then
              If (zoom = 15) Then
                  lng -= 0.003
              ElseIf (zoom &gt; 15) Then
                  diff = zoom - 15
                  shift = ((15 - diff) * 0.003) / 15
                  lng -= shift
              Else
                  diff = 15 - zoom
                  shift = ((15 + diff) * 0.003) / 15
                  lng -= shift
              End If
              ShowMapUsingLatLng()
          Else
              lng = 180
          End If
      End Sub
  
      Private Sub MoveRight()
          Dim diff As Double
          Dim shift As Double
          If (lng &lt; 178) Then
              If (zoom = 15) Then
                  lng += 0.003
              ElseIf (zoom &gt; 15) Then
                  diff = zoom - 15
                  shift = ((15 - diff) * 0.003) / 15
                  lng += shift
              Else
                  diff = 15 - zoom
                  shift = ((15 + diff) * 0.003) / 15
                  lng += shift
              End If
              ShowMapUsingLatLng()
          Else
              lng = -180
          End If
      End Sub
  
      Private Sub DisplayXXXXXXs()
          AddressTxtBlck.Text = "XXXXXXXXX, XXXXX, XXXXXX"
          LatitudeTxtBlck.Text = "XXXXXXXXXX"
          LongitudeTxtBlck.Text = "XXXXXXXXXX"
          AccuracyTxtBlck.Text = "XXXXXXXXX"
      End Sub
  
      Private Sub HideProgressBar()
          MapProgressBar.Visibility = Windows.Visibility.Hidden
          ShowMapButton.IsEnabled = True
      End Sub
  
      ' ShowMapButton click event handler.
      Private Sub ShowMapButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ShowMapButton.Click
          If (AddressTxtBox.Text &lt;&gt; String.Empty) Then
              location = AddressTxtBox.Text.Replace(" ", "+")
              zoom = 15
              mapType = "roadmap"
              Dim geoThread As New Thread(AddressOf GetGeocodeData)
              geoThread.Start()
  
              ShowMapImage()
              AddressTxtBox.SelectAll()
              ShowMapButton.IsEnabled = False
              MapProgressBar.Visibility = Windows.Visibility.Visible
  
              If (RoadmapToggleButton.IsChecked = False) Then
                  RoadmapToggleButton.IsChecked = True
                  TerrainToggleButton.IsChecked = False
              End If
          Else
              MessageBox.Show("Enter location address.", _
                              "Map App", MessageBoxButton.OK, MessageBoxImage.Exclamation)
              AddressTxtBox.Focus()
          End If
      End Sub
  
      ' SaveFileDialog FileOk event handler.
      Private Sub saveDialog_FileOk(ByVal sender As Object, ByVal e As EventArgs)
          Dim td As New Thread(AddressOf SaveMap)
          td.Start()
      End Sub
  
      ' ZoomInButton click event handler.
      Private Sub ZoomInButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ZoomInButton.Click
          ZoomIn()
      End Sub
  
      ' ZoomOutButton click event handler.
      Private Sub ZoomOutButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ZoomOutButton.Click
          ZoomOut()
      End Sub
  
      ' SaveButton click event handler.
      Private Sub SaveButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles SaveButton.Click
          saveDialog.ShowDialog()
      End Sub
  
      ' RoadmapToggleButton Checked event handler.
      Private Sub RoadmapToggleButton_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles RoadmapToggleButton.Checked
          If (mapType &lt;&gt; "roadmap") Then
              mapType = "roadmap"
              ShowMapUsingLatLng()
              TerrainToggleButton.IsChecked = False
          End If
      End Sub
  
      ' TerrainToggleButton Checked event handler.
      Private Sub TerrainToggleButton_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles TerrainToggleButton.Checked
          If (mapType &lt;&gt; "terrain") Then
              mapType = "terrain"
              ShowMapUsingLatLng()
              RoadmapToggleButton.IsChecked = False
          End If
      End Sub
  
      Private Sub MapImage_MouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles MapImage.MouseLeftButtonUp
          If (location IsNot Nothing) Then
              Dim gMapURL As String = "http://maps.google.com/maps?q=" &amp; location
              Process.Start("IExplore.exe", gMapURL)
          End If
      End Sub
  
      Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
          AddressTxtBox.Focus()
  
          With saveDialog
              .DefaultExt = "png"
              .Title = "Save Map Image"
              .OverwritePrompt = True
              .Filter = "(*.png)|*.png"
          End With
  
          AddHandler saveDialog.FileOk, AddressOf saveDialog_FileOk
      End Sub
  
      Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
          Me.WindowState = Windows.WindowState.Minimized
      End Sub
  
      Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
          Me.Close()
      End Sub
  //ds
      Private Sub BgndRectangle_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles BgndRectangle.MouseLeftButtonDown
          Me.DragMove()
      End Sub
  //df
      Private Sub MoveUpButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MoveUpButton.Click
          MoveUp()
      End Sub
  //sdf
      Private Sub MoveDownButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MoveDownButton.Click
          MoveDown()
      End Sub
  
      Private Sub MoveLeftButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MoveLeftButton.Click
          MoveLeft()
      End Sub
  
      Private Sub MoveRightButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MoveRightButton.Click
          MoveRight()
      End Sub
     
  End Class</code></pre>
  </div>
  </div>
  
  i have this class for searching through google maps.
  how can i pass it a location so that on startup it can show the given location on the map?</p>