{"id":38019,"date":"2013-06-04T08:17:36","date_gmt":"2013-06-04T08:17:36","guid":{"rendered":"https:\/\/www.viafirma.com\/google-geocoding-api-in-excel-i\/"},"modified":"2026-01-21T10:45:57","modified_gmt":"2026-01-21T10:45:57","slug":"google-geocoding-api-in-excel-i","status":"publish","type":"post","link":"https:\/\/www.viafirma.com\/en\/google-geocoding-api-in-excel-i\/","title":{"rendered":"Google Geocoding API in Excel (I)"},"content":{"rendered":"\r\n<p>Reading a post about how geolocation can be used as electronic evidence, a task that I recently had the good fortune to start came to my mind, perhaps not very relevant, but quite attractive, since, even if in a second phase it was somewhat automatic, it is always nice to do work where you end up with new ideas and\/or knowledge.<\/p>\r\n<p>The objective of the task was<strong> to obtain from the addresses of an Excel document<\/strong> (complete addresses, names of countries, communities, provinces or municipalities&#8230;) their coordinates on the map. This transformation is known as <strong>Geolocation<\/strong> and although at first you might think that it would be something complicated or expensive to obtain, the truth is that it is quite fast and effective results.<\/p>\r\n<p>All this thanks to the <strong>Google API for Geolocation<\/strong>, with which we get that, making a query in which <strong>we send a URL with the data of the address we want,<\/strong> we get an XML with all the information of that location, including what we needed: <strong>latitude and longitude.<\/strong><\/p>\r\n<p>If we click on the following link we will see that we obtain the geolocation of the office where I am \ud83d\ude42<\/p>\r\n<p>http:\/\/maps.googleapis.com\/maps\/api\/geocode\/xml?address=Glorieta%20Fernando%20Qui%C3%B1ones&#038;sensor=false<\/p>\r\n<p>Next, I am going to explain the steps that we must take to obtain our document with all the necessary coordinates.<\/p>\r\n<p>To do this, first indicate that we will use the <strong>2010 version of Excel.<\/strong><\/p>\r\n<p>We<strong> will need to have the &#8220;Scheduler&#8221; tab visible<\/strong> since this is where we are going to start the geolocation process.<\/p>\r\n<p>To enable this tab, go to the<strong> File menu, Options.<\/strong><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4957\" title=\"Archivo_Opciones\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/Archivo_Opciones.png\" alt=\"\" width=\"1084\" height=\"459\" \/><\/p>\r\n<p>Click on <strong>&#8220;Customize ribbon&#8221;<\/strong>, select <strong>&#8220;Main tabs&#8221;<\/strong> in the drop-down menu under the heading of the same name, select the <strong>&#8220;Scheduler&#8221;<\/strong> checkbox and click on the &#8220;<strong>OK<\/strong>&#8221; button.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4958\" title=\"Opciones_Programador\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/Opciones_Programador.png\" alt=\"\" width=\"952\" height=\"684\" \/><\/p>\r\n<p>Once these steps have been completed, we can see the <strong>Scheduler<\/strong> option as another tab.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4964\" title=\"Tab_Programador\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/Tab_Programador.png\" alt=\"\" width=\"638\" height=\"25\" \/><\/p>\r\n<p>We now need <strong>to run the VisualBasic command in Excel<\/strong> to create our function.<\/p>\r\n<p>Therefore we click on the icon that gives us this option:<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4959\" title=\"Visual_Basic_Programador\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/Visual_Basic_Programador.png\" alt=\"\" width=\"1067\" height=\"237\" \/><\/p>\r\n<p>A new screen opens.<\/p>\r\n<p>Select &#8220;<strong>Insert<\/strong>&#8221; and then &#8220;<strong>Module<\/strong>&#8220;.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4960\" title=\"VB_Module\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/VB_Module.png\" alt=\"\" width=\"734\" height=\"770\" \/><\/p>\r\n<p>And <strong>we copy the following code<\/strong> in the module that has been created.<\/p>\r\n<p>On the internet there are many variants of code to get what we want. I used this one and I can say that it worked quite well.<\/p>\r\n<pre><code>Function GoogleGeocode(address As String) As String\r\n  Dim strAddress As String\r\n  Dim strQuery As String\r\n  Dim strLatitude As String\r\n  Dim strLongitude As String\r\n\r\n  strAddress = URLEncode(address)\r\n\r\n  'Assemble the query string\r\n  strQuery = \"http:\/\/maps.googleapis.com\/maps\/api\/geocode\/xml?\"\r\n  strQuery = strQuery &amp; \"address=\" &amp; strAddress\r\n  strQuery = strQuery &amp; \"&amp;sensor=false\"\r\n\r\n  'define XML and HTTP components\r\n  Dim googleResult As New MSXML2.DOMDocument\r\n  Dim googleService As New MSXML2.XMLHTTP\r\n  Dim oNodes As MSXML2.IXMLDOMNodeList\r\n  Dim oNode As MSXML2.IXMLDOMNode\r\n\r\n  'create HTTP request to query URL - make sure to have\r\n  'that last \"False\" there for synchronous operation\r\n\r\n  googleService.Open \"GET\", strQuery, False\r\n  googleService.send\r\n  googleResult.LoadXML (googleService.responseText)\r\n\r\n  Set oNodes = googleResult.getElementsByTagName(\"geometry\")\r\n\r\n  If oNodes.Length = 1 Then\r\n    For Each oNode In oNodes\r\n      strLatitude = oNode.ChildNodes(0).ChildNodes(0).Text\r\n      strLongitude = oNode.ChildNodes(0).ChildNodes(1).Text\r\n      GoogleGeocode = strLatitude &amp; \",\" &amp; strLongitude\r\n    Next oNode\r\n  Else\r\n    GoogleGeocode = \"Not Found (try again, you may have done too many too fast)\"\r\n  End If\r\nEnd Function\r\n\r\nPublic Function URLEncode(StringVal As String, Optional SpaceAsPlus As Boolean = False) As String\r\n  Dim StringLen As Long: StringLen = Len(StringVal)\r\n\r\n  If StringLen&gt;0 Then\r\n    ReDim result(StringLen) As String\r\n    Dim i As Long, CharCode As Integer\r\n    Dim Char As String, Space As String\r\n\r\n    If SpaceAsPlus Then Space = \"+\" Else Space = \"%20\"\r\n\r\n    For i = 1 To StringLen\r\n      Char = Mid$(StringVal, i, 1)\r\n      CharCode = Asc(Char)\r\n\r\n      Select Case CharCode\r\n      Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126\r\n        result(i) = Char\r\n      Case 32\r\n        result(i) = Space\r\n      Case 0 To 15\r\n        result(i) = \"%0\" &amp; Hex(CharCode)\r\n      Case Else\r\n        result(i) = \"%\" &amp; Hex(CharCode)\r\n      End Select\r\n    Next i\r\n    URLEncode = Join(result, \"\")\r\n  End If\r\nEnd Function\r\n\r\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4963\" title=\"Module_1_Code\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/Module_1_Code.png\" alt=\"\" width=\"1346\" height=\"1033\" \/><\/code><\/pre>\r\n<p>The code makes use of the Microsoft XML library so <strong>we will have to add a reference to it<\/strong>. To do this <strong>we click on the &#8220;Tools&#8221; menu option and select &#8220;References&#8221;.<\/strong><\/p>\r\n<p lang=\"es-ES\">\u00a0<\/p>\r\n<p lang=\"es-ES\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4961     alignnone\" title=\"Herramientas_Referencias\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/Herramientas_Referencias.png\" alt=\"\" width=\"723\" height=\"226\" \/><\/p>\r\n<p lang=\"es-ES\">\u00a0<\/p>\r\n<p lang=\"es-ES\">\u00a0<\/p>\r\n<p lang=\"es-ES\">A list of checkboxes will appear. <strong>We need to find &#8220;Microsoft XML v6.0&#8221;<\/strong> in the list and check that it works. Click &#8220;<strong>OK<\/strong>&#8220;.<\/p>\r\n<p lang=\"es-ES\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4962\" title=\"referencias_MXML_6\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2013\/05\/referencias_MXML_6.png\" alt=\"\" width=\"465\" height=\"374\" \/><\/p>\r\n<p>Save the document as <strong>&#8220;Excel workbook enabled for macros&#8221;.<\/strong><\/p>\r\n<p>If we have done all the steps correctly we should be able to use the newly created functions as we would use the default Excel loaded functions.<\/p>\r\n<p>That is, by standing in any cell and typing the following:<\/p>\r\n<p lang=\"es-ES\"><strong>=GoogleGeocode(A646)<\/strong><\/p>\r\n<p>The code above serves as an example.<\/p>\r\n<p>Of course, in this geolocation process I encountered some problems, some perfectly avoidable and others with which we can do absolutely nothing, at least as far as I know. But that will be a matter for another day, since the post is getting a little long already :).<\/p>\r\n<p><span style=\"font-weight: 400;\"><div class=\"vf_related_posts_wrapper\"><h2 class=\"vf_related_posts_title\">Informaci\u00f3n relacionada<\/h2><div class=\"vf_related_posts\"><article class=\"vc_gitem-post-data-source-post\"><a href=\"https:\/\/www.viafirma.com\/en\/google-esignature\/\"><div class=\"vc_gitem-post-image\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"475\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2023\/09\/img_blog_firmadigital_google-768x475.webp\" class=\"attachment-medium_large size-medium_large wp-post-image\" alt=\"Comparison between Viafirma&#039;s digital signature and Google eSignature\" srcset=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2023\/09\/img_blog_firmadigital_google-768x475.webp 768w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2023\/09\/img_blog_firmadigital_google-300x186.webp 300w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2023\/09\/img_blog_firmadigital_google-1024x634.webp 1024w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2023\/09\/img_blog_firmadigital_google.jpg 1228w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/div><\/a><div class=\"vc_gitem-post-data\"><h3 class=\"vc_gitem-post-data-source-post_title\"><a href=\"https:\/\/www.viafirma.com\/en\/google-esignature\/\">Google esignature<\/a><\/h3><p>Google eSignature vs Viafirma: A New Digital Signature Feature<\/p><\/div><\/article><article class=\"vc_gitem-post-data-source-post\"><a href=\"https:\/\/www.viafirma.com\/en\/clear-cache-on-any-web-browser\/\"><div class=\"vc_gitem-post-image\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"475\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2020\/10\/blog_navegador-768x475.webp\" class=\"attachment-medium_large size-medium_large wp-post-image\" alt=\"Ordenador sobre mesa con una pesta\u00f1a abierta\" srcset=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2020\/10\/blog_navegador-768x475.webp 768w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2020\/10\/blog_navegador-300x186.webp 300w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2020\/10\/blog_navegador-1024x634.webp 1024w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2020\/10\/blog_navegador.webp 1228w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/div><\/a><div class=\"vc_gitem-post-data\"><h3 class=\"vc_gitem-post-data-source-post_title\"><a href=\"https:\/\/www.viafirma.com\/en\/clear-cache-on-any-web-browser\/\">Clear cache on any web browser<\/a><\/h3><p>To clear cache from Google Chrome, follow the steps below:<\/p><\/div><\/article><article class=\"vc_gitem-post-data-source-post\"><a href=\"https:\/\/www.viafirma.com\/en\/what-is-advanced-electronic-signature\/\"><div class=\"vc_gitem-post-image\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"512\" src=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2021\/05\/Que-es-la-firma-electronica-avanzada-768x512.webp\" class=\"attachment-medium_large size-medium_large wp-post-image\" alt=\"que-es-la-firma-electronica-avanzada\" srcset=\"https:\/\/www.viafirma.com\/wp-content\/uploads\/2021\/05\/Que-es-la-firma-electronica-avanzada-768x512.webp 768w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2021\/05\/Que-es-la-firma-electronica-avanzada-300x200.webp 300w, https:\/\/www.viafirma.com\/wp-content\/uploads\/2021\/05\/Que-es-la-firma-electronica-avanzada.webp 1024w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/div><\/a><div class=\"vc_gitem-post-data\"><h3 class=\"vc_gitem-post-data-source-post_title\"><a href=\"https:\/\/www.viafirma.com\/en\/what-is-advanced-electronic-signature\/\">What is advanced electronic signature?<\/a><\/h3><p>Are you wondering what an advanced electronic signature is? In<\/p><\/div><\/article><\/div><\/div><\/span><\/p>\r\n","protected":false},"excerpt":{"rendered":"Reading a post about how geolocation can be used as...","protected":false},"author":1,"featured_media":35629,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[157],"class_list":["post-38019","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-others"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/posts\/38019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/comments?post=38019"}],"version-history":[{"count":2,"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/posts\/38019\/revisions"}],"predecessor-version":[{"id":97430,"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/posts\/38019\/revisions\/97430"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/media\/35629"}],"wp:attachment":[{"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/media?parent=38019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.viafirma.com\/en\/wp-json\/wp\/v2\/categories?post=38019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}