Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the modGoogleMapsAPI module. |
LatitudeLongitudeFromAddress | Procedure | Translates an address into GPS latitude and longitude coordinates using Google Maps API web service and XML parsing. |
AddressType | Procedure | Use the Google Maps API web service and XML parsing to determine the type of a location. |
AddressElementArrays | Procedure | Use the Google Maps API web service and XML parsing to get all the components of an address and return them in arrays. |
AddressComponents | Procedure | Use the Google Maps API web service and XML parsing to get an address's primary components (some may not exist depending on the address). |
GoogleGeocodeXML | Procedure | Get the XML return value for an address using Google Maps API web service. |
InvokeWebService | Procedure | Call a web page, pass it commands, and returns the value. |
' Example of modGoogleMapsAPI ' ' To use this example, create a new module and paste this code into it. ' Then run these procedures by putting the cursor in the procedure and pressing: ' F5 to run it, or ' F8 to step through it line-by-line (see the Debug menu for more options) ' View the results in the immediate window. Private Const mcstrAddressFMS As String = "8150 Leesburg Pike, Vienna, VA 22182" Private Const mcstrAddressTest As String = "White House" Private Const mcstrZipCode As String = "22102" Private Const mcstrAirport As String = "IAD" ' Dulles Aiport Private Sub Example_LatitudeLongitudeFromAddress() ' Comments: Example of modGoogleMapsAPI module to get the GPS latitude and longitude for an address using the Google API in VBA and VB6. Dim dblLatitude As Double, dblLongitude As Double Debug.Print "* Address Latitude and Longitude *" ' Latitude and Longitude for the FMS office If LatitudeLongitudeFromAddress(mcstrAddressFMS, dblLatitude, dblLongitude) Then Debug.Print "FMS Offices", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for the White House If LatitudeLongitudeFromAddress(mcstrAddressTest, dblLatitude, dblLongitude) Then Debug.Print mcstrAddressTest, "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for Dulles International Airport If LatitudeLongitudeFromAddress(mcstrAirport, dblLatitude, dblLongitude) Then Debug.Print mcstrAirport & " Airport", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for Pan American Health Organization Headquarters If LatitudeLongitudeFromAddress("PAHO, 525 23rd Street, NW, Washington, DC 20037", dblLatitude, dblLongitude) Then Debug.Print "PAHO", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for the National Archives If LatitudeLongitudeFromAddress("National Archives, Washington DC", dblLatitude, dblLongitude) Then Debug.Print "Natl Archives", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for Microsoft Headquarters If LatitudeLongitudeFromAddress("Microsoft, Redmond, WA", dblLatitude, dblLongitude) Then Debug.Print "Microsoft", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for China's Forbidden City If LatitudeLongitudeFromAddress("Forbidden City, Beijing, China", dblLatitude, dblLongitude) Then Debug.Print "Beijing", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for a Country near Greenwich (0 degrees longitude) If LatitudeLongitudeFromAddress("United Kingdom", dblLatitude, dblLongitude) Then Debug.Print "UK", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for a Country near the equator (0 degrees latitude) If LatitudeLongitudeFromAddress("Galapagos Islands", dblLatitude, dblLongitude) Then Debug.Print "Galapagos", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for a Country near the equator (0 degrees latitude) If LatitudeLongitudeFromAddress("Sydney Opera House", dblLatitude, dblLongitude) Then Debug.Print "Australia", "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If ' Latitude and Longitude for a zip code If LatitudeLongitudeFromAddress(mcstrZipCode, dblLatitude, dblLongitude) Then Debug.Print "Zip " & mcstrZipCode, "Latitude: " & dblLatitude, "Longitude: " & dblLongitude End If End Sub Private Sub Example_AddressType() ' Comments: Determine the type of a location as provided by the XML file returned by the Google API in VBA and VB6. Dim strType As String Debug.Print "* Address Types *" ' Get the type for a standard address strType = AddressType(mcstrAddressFMS) Debug.Print "FMS Offices", strType ' Get the type for the name of a location strType = AddressType(mcstrAddressTest) Debug.Print mcstrAddressTest, strType ' Get the type for Dulles International Airport strType = AddressType(mcstrAirport) Debug.Print mcstrAirport & " Airport", strType ' Get the type for a US zip code strType = AddressType(mcstrZipCode) Debug.Print "Zip " & mcstrZipCode, strType ' Get the type for a city strType = AddressType("Vienna") Debug.Print "Vienna", strType ' Get the type for a state strType = AddressType("California") Debug.Print "CA", strType ' Get the type for a country strType = AddressType("United Kingdom") Debug.Print "UK", strType End Sub Private Sub Example_AddressElementArrays() ' Comments: Create an array of all the component parts of an address as provided by the XML file returned by the Google API in VBA and VB6. Dim astrTypes() As String, astrLongName() As String, astrShortName() As String Dim intCount As Integer If AddressElementArrays(mcstrAddressFMS, astrTypes(), astrLongName(), astrShortName()) Then Debug.Print "* Address Elements *" Debug.Print "Item", "Type", "Long Name", "Short Name" For intCount = 1 To UBound(astrTypes) Debug.Print intCount, astrTypes(intCount), astrLongName(intCount), astrShortName(intCount) Next intCount End If End Sub Private Sub Example_AddressComponents() ' Comments: Retrieve the basic components of an address as provided by the XML file returned by the Google API in VBA and VB6. Dim strStreetNumber As String, strRoute As String, strCity As String, strState As String, strPostalCode As String Dim strCountry As String, strCounty As String If AddressComponents(mcstrAddressFMS, strStreetNumber, strRoute, strCity, strState, strPostalCode, strCountry, strCounty) Then Debug.Print "* Address Components *" Debug.Print "StreetNumber", strStreetNumber Debug.Print "Route", strRoute Debug.Print "City", strCity Debug.Print "State", strState Debug.Print "PostalCode", strPostalCode Debug.Print "Country", strCountry Debug.Print "County", strCounty End If End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP