title: Code to Get GPS Coordinates from Address (VB/VB.Net/VBA/VBScript)
body: <p>I believe the Google API allows you to get coordinates for a given address. However, most (or should I say all) of the examples I've found aren't for vb. Usually it's some javascript example that just leaves me confused.</p>
  
  <p>Here's some code I have that uses a geocoding service. This works great. It's just that I want to query Google Maps directly myself.</p>
  
  <pre><code>Public Function fgGetLatAndLongUsingAddress(sAddress As String) As String
  
      'This function works best with a complete address including the zip code
      Dim sResponseText As String, sReturn As String
  
      sReturn = "none"
  
      Dim objHttp As Object, sQuery As String
      sQuery = "http://rpc.geocoder.us/service/csv?address=" &amp; Replace(sAddress, " ", "+")
      Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
      objHttp.Open "GET", sQuery, False
      objHttp.send
      sResponseText = objHttp.ResponseText
      gsLastLatLongResponseText = sResponseText
      Set objHttp = Nothing
  
  
      If Len(sResponseText) &gt; 0 Then
          If InStr(sResponseText, "Bad Request") &gt; 0 Then
              'Do Nothing
          ElseIf InStr(sResponseText, "couldn't find this address") &gt; 0 Then
              'Do Nothing
          Else
              If InStr(sResponseText, vbCrLf) &gt; 0 Then
                  'We got more than one result
              End If
              If InStr(sResponseText, ",") &gt; 0 Then
                  Dim aryInfo() As String
                  aryInfo = Split(sResponseText, ",")
                  sReturn = aryInfo(0) &amp; "," &amp; aryInfo(1)
              End If
          End If
      End If
  
  
      fgGetLatAndLongUsingAddress = sReturn
  
  End Function
  </code></pre>