Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should do the job. You need to add a reference to the MSXML6 library (Microsoft XML, v6.0) via Tools > References in Excel</p> <pre><code>Option Explicit Function getGoogleMapsGeocode(sAddr As String) As String Dim xhrRequest As XMLHTTP60 Dim sQuery As String Dim domResponse As DOMDocument60 Dim ixnStatus As IXMLDOMNode Dim ixnLat As IXMLDOMNode Dim ixnLng As IXMLDOMNode ' Use the empty string to indicate failure getGoogleMapsGeocode = "" Set xhrRequest = New XMLHTTP60 sQuery = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&amp;address=" sQuery = sQuery &amp; Replace(sAddr, " ", "+") xhrRequest.Open "GET", sQuery, False xhrRequest.send Set domResponse = New DOMDocument60 domResponse.loadXML xhrRequest.responseText Set ixnStatus = domResponse.selectSingleNode("//status") If (ixnStatus.Text &lt;&gt; "OK") Then Exit Function End If Set ixnLat = domResponse.selectSingleNode("/GeocodeResponse/result/geometry/location/lat") Set ixnLng = domResponse.selectSingleNode("/GeocodeResponse/result/geometry/location/lng") getGoogleMapsGeocode = ixnLat.Text &amp; ", " &amp; ixnLng.Text End Function </code></pre> <p>The only real differences to your example are:</p> <ul> <li>changing the URL and parameters of the query to use the Google API</li> <li>treating the response as an XML document and using <a href="http://www.w3schools.com/XPath/default.asp" rel="nofollow">XPath</a> to extract the required results</li> </ul> <p>Obviously there's no error handling whatsoever in my code but it should give you an idea of what you need to use the API. You definitely want to consult the <a href="http://code.google.com/apis/maps/documentation/geocoding/" rel="nofollow">API documentation</a> yourself to find out about rate limiting etc</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload