{"id":17221,"date":"2025-01-20T15:15:16","date_gmt":"2025-01-20T06:15:16","guid":{"rendered":"https:\/\/84office.jp\/?p=17221"},"modified":"2025-01-20T15:15:17","modified_gmt":"2025-01-20T06:15:17","slug":"run-google-maps-api-geocoding","status":"publish","type":"post","link":"https:\/\/84office.jp\/en\/run-google-maps-api-geocoding\/","title":{"rendered":"How to Automatically Convert Addresses to Latitude and Longitude in Google Sheets Using Google Maps API"},"content":{"rendered":"<div class=\"codoc-evacuations\" style=\"display:none;\" data-shortcode=\"\"><\/div>\n<p>In the previous article, we introduced how to obtain an API key for using the Google Maps API.<\/p>\n\n\n\n<p>In this article, we will show you how to use the Google Maps API to automatically output latitude and longitude from addresses in Google Sheets.<\/p>\n\n\n\n<p>By following the steps, you&#8217;ll be able to set it up easily.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-40\">For details on how to obtain an API key, please refer to [<a href=\"https:\/\/84office.jp\/en\/get-google-maps-api-geocoding\/\">this article<\/a>].<\/p>\n\n\n<div class=\"swell-block-postLink u-mb-ctrl u-mb-60\">\t\t\t<div class=\"p-blogCard -internal\" data-type=\"type1\" data-onclick=\"clickLink\">\n\t\t\t\t<div class=\"p-blogCard__inner\">\n\t\t\t\t\t<span class=\"p-blogCard__caption\">\u3042\u308f\u305b\u3066\u8aad\u307f\u305f\u3044<\/span>\n\t\t\t\t\t<div class=\"p-blogCard__thumb c-postThumb\"><figure class=\"c-postThumb__figure\"><img decoding=\"async\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/a98b1120712ae2558c294773114e59b3-3-300x158.png\" alt=\"\" class=\"c-postThumb__img u-obf-cover\" width=\"320\" height=\"180\"><\/figure><\/div>\t\t\t\t\t<div class=\"p-blogCard__body\">\n\t\t\t\t\t\t<a class=\"p-blogCard__title\" href=\"https:\/\/84office.jp\/en\/get-google-maps-api-geocoding\/\">How to Get a Google Maps API Key: Retrieve Latitude and Longitude from Addresses in Google Sheets<\/a>\n\t\t\t\t\t\t<span class=\"p-blogCard__excerpt\">Have you ever wanted to automatically retrieve latitude and longitude from addresses to enhance data analysis or improve workflow efficiency? With the Google&#8230;<\/span>\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n\n\n<h2 class=\"wp-block-heading\">Example Output<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"407\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-72-1024x407.png\" alt=\"\" class=\"wp-image-17229\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-72-1024x407.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-72-300x119.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-72-768x305.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-72.png 1388w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-border -border02 u-mb-ctrl u-mb-60 has-swl-pale-03-background-color has-background\">When you input an address in column A and run the script, the latitude and longitude are automatically output to columns B and C, respectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Preparing the Spreadsheet<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"409\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-73-1024x409.png\" alt=\"\" class=\"wp-image-17230\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-73-1024x409.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-73-300x120.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-73-768x307.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-73.png 1389w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Input addresses in column A.<\/li>\n\n\n\n<li class=\"u-mb-ctrl u-mb-40\">Use the first row as the header row.<\/li>\n<\/ul>\n\n\n\n<p>The sheet should be named <strong>&#8220;GeoData&#8221;<\/strong>, as the script will reference this name during execution.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-60\">If you want to use a different sheet name, you will need to modify the script accordingly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Executing Google Apps Script<\/strong><\/h3>\n\n\n\n<div class=\"swell-block-step u-mb-ctrl u-mb-60\" data-num-style=\"circle\">\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\">Open Apps Script Editor<\/div><div class=\"swell-block-step__body\"><div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-full is-resized\"><img decoding=\"async\" width=\"933\" height=\"591\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d.png\" alt=\"\" class=\"wp-image-16537\" style=\"width:447px;height:auto\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d.png 933w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d-300x190.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d-768x486.png 768w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/figure>\n<\/div>\n\n\n<p>Open a Google Spreadsheet and click on \u201c<strong>Extensions<\/strong>\u201d in the menu, then \u201c<strong>Apps Script<\/strong>\u201d to open the Apps Script editor.<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\"><strong>Create the Script<\/strong><\/div><div class=\"swell-block-step__body\"><div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"1024\" height=\"472\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-1024x472.png\" alt=\"\" class=\"wp-image-16191\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-1024x472.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-300x138.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-768x354.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662.png 1387w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"u-mb-ctrl u-mb-40\">Since the default <code>function myFunction() {}<\/code> is present, delete it and replace it with the script below.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"function getLatLng() {\n  \/\/ Specify the fixed sheet name\n  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('GeoData');\n\n  \/\/ Retrieve addresses from column A (starting from row 2 to the last row)\n  const range = sheet.getRange(2, 1, sheet.getLastRow() - 1);\n  const addresses = range.getValues();\n  \n  \/\/ Get the API key from script properties\n  const apiKey = PropertiesService.getScriptProperties().getProperty(&quot;Maps_API_KEY&quot;);\n  if (!apiKey) {\n    throw new Error(&quot;API key is not set. Please add 'Maps_API_KEY' to the script properties.&quot;);\n  }\n\n  \/\/ Fetch latitude and longitude for each address\n  for (let i = 0; i &lt; addresses.length; i++) {\n    const address = addresses[i][0]; \/\/ Get the address\n    if (address) {\n      const response = UrlFetchApp.fetch(\n        `https:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=${encodeURIComponent(address)}&amp;key=${apiKey}`\n      );\n      const data = JSON.parse(response.getContentText());\n\n      if (data.status === &quot;OK&quot;) {\n        const location = data.results[0].geometry.location;\n        sheet.getRange(i + 2, 2).setValue(location.lat); \/\/ Write latitude to column B\n        sheet.getRange(i + 2, 3).setValue(location.lng); \/\/ Write longitude to column C\n      } else {\n        sheet.getRange(i + 2, 2).setValue(&quot;Error&quot;); \/\/ Handle errors\n        sheet.getRange(i + 2, 3).setValue(&quot;Error&quot;);\n      }\n    }\n  }\n}\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">function<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">getLatLng<\/span><span style=\"color: #F8F8F2\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Specify the fixed sheet name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> sheet <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> SpreadsheetApp.<\/span><span style=\"color: #A6E22E\">getActiveSpreadsheet<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getSheetByName<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&#39;GeoData&#39;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Retrieve addresses from column A (starting from row 2 to the last row)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> range <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">, sheet.<\/span><span style=\"color: #A6E22E\">getLastRow<\/span><span style=\"color: #F8F8F2\">() <\/span><span style=\"color: #F92672\">-<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> addresses <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> range.<\/span><span style=\"color: #A6E22E\">getValues<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Get the API key from script properties<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> apiKey <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> PropertiesService.<\/span><span style=\"color: #A6E22E\">getScriptProperties<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getProperty<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Maps_API_KEY&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #F92672\">!<\/span><span style=\"color: #F8F8F2\">apiKey) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">throw<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #F92672\">new<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">Error<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;API key is not set. Please add &#39;Maps_API_KEY&#39; to the script properties.&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Fetch latitude and longitude for each address<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">for<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #66D9EF; font-style: italic\">let<\/span><span style=\"color: #F8F8F2\"> i <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">; i <\/span><span style=\"color: #F92672\">&lt;<\/span><span style=\"color: #F8F8F2\"> addresses.length; i<\/span><span style=\"color: #F92672\">++<\/span><span style=\"color: #F8F8F2\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> address <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> addresses[i][<\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">]; <\/span><span style=\"color: #88846F\">\/\/ Get the address<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (address) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> response <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> UrlFetchApp.<\/span><span style=\"color: #A6E22E\">fetch<\/span><span style=\"color: #F8F8F2\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        <\/span><span style=\"color: #E6DB74\">`https:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #A6E22E\">encodeURIComponent<\/span><span style=\"color: #F8F8F2\">(address)<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">&amp;key=<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">apiKey<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">`<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> data <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> JSON.<\/span><span style=\"color: #A6E22E\">parse<\/span><span style=\"color: #F8F8F2\">(response.<\/span><span style=\"color: #A6E22E\">getContentText<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (data.status <\/span><span style=\"color: #F92672\">===<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">&quot;OK&quot;<\/span><span style=\"color: #F8F8F2\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> location <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> data.results[<\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">].geometry.location;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(location.lat); <\/span><span style=\"color: #88846F\">\/\/ Write latitude to column B<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">3<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(location.lng); <\/span><span style=\"color: #88846F\">\/\/ Write longitude to column C<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      } <\/span><span style=\"color: #F92672\">else<\/span><span style=\"color: #F8F8F2\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Error&quot;<\/span><span style=\"color: #F8F8F2\">); <\/span><span style=\"color: #88846F\">\/\/ Handle errors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">3<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Error&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"swell-block-accordion\">\n<details class=\"swell-block-accordion__item\" data-swl-acc=\"wrapper\"><summary class=\"swell-block-accordion__title\" data-swl-acc=\"header\"><span class=\"swell-block-accordion__label\">Script Description<\/span><span class=\"swell-block-accordion__icon c-switchIconBtn\" data-swl-acc=\"icon\" aria-hidden=\"true\" data-opened=\"false\"><i class=\"__icon--closed icon-caret-down\"><\/i><i class=\"__icon--opened icon-caret-up\"><\/i><\/span><\/summary><div class=\"swell-block-accordion__body\" data-swl-acc=\"body\">\n<dl class=\"swell-block-dl\">\n<dt class=\"swell-block-dl__dt\"><strong>Retrieving the Sheet<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('GeoData');\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> sheet <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> SpreadsheetApp.<\/span><span style=\"color: #A6E22E\">getActiveSpreadsheet<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getSheetByName<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&#39;GeoData&#39;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Specify the sheet name to access the desired sheet.<\/li>\n\n\n\n<li>If you want to change the sheet name, replace <code>'GeoData'<\/code> with your actual sheet name (e.g., <code>'AddressList'<\/code>).<\/li>\n<\/ul>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Retrieving Addresses<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"  const range = sheet.getRange(2, 1, sheet.getLastRow() - 1);\n  const addresses = range.getValues();\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> range <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">, sheet.<\/span><span style=\"color: #A6E22E\">getLastRow<\/span><span style=\"color: #F8F8F2\">() <\/span><span style=\"color: #F92672\">-<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> addresses <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> range.<\/span><span style=\"color: #A6E22E\">getValues<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Access the range of column A (where the addresses are entered) from the second row to the last row.<\/li>\n\n\n\n<li>The data is retrieved in an array format. It is assumed that the first row is a header row, and the data starts from the second row onward.<\/li>\n<\/ul>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Retrieving the API Key<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"  const apiKey = PropertiesService.getScriptProperties().getProperty(&quot;Maps_API_KEY&quot;);\n  if (!apiKey) {\n    throw new Error(&quot;API key is not set. Please add 'Maps_API_KEY' to the script properties.&quot;);\n  }\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> apiKey <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> PropertiesService.<\/span><span style=\"color: #A6E22E\">getScriptProperties<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getProperty<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Maps_API_KEY&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #F92672\">!<\/span><span style=\"color: #F8F8F2\">apiKey) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">throw<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #F92672\">new<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">Error<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;API key is not set. Please add &#39;Maps_API_KEY&#39; to the script properties.&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The script retrieves the API key named <code>Maps_API_KEY<\/code> from the script properties.<\/li>\n\n\n\n<li>If the API key is not set, an error will be thrown. Ensure the API key is registered in the script properties beforehand.<\/li>\n<\/ul>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Geocoding Each Address (Converting to Latitude and Longitude)<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"  for (let i = 0; i &lt; addresses.length; i++) {\n    const address = addresses[i][0]; \/\/ Get the address\n    if (address) {\n      const response = UrlFetchApp.fetch(\n        `https:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=${encodeURIComponent(address)}&amp;key=${apiKey}`\n      );\n      const data = JSON.parse(response.getContentText());\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">for<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #66D9EF; font-style: italic\">let<\/span><span style=\"color: #F8F8F2\"> i <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">; i <\/span><span style=\"color: #F92672\">&lt;<\/span><span style=\"color: #F8F8F2\"> addresses.length; i<\/span><span style=\"color: #F92672\">++<\/span><span style=\"color: #F8F8F2\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> address <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> addresses[i][<\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">]; <\/span><span style=\"color: #88846F\">\/\/ Get the address<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (address) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> response <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> UrlFetchApp.<\/span><span style=\"color: #A6E22E\">fetch<\/span><span style=\"color: #F8F8F2\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        <\/span><span style=\"color: #E6DB74\">`https:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #A6E22E\">encodeURIComponent<\/span><span style=\"color: #F8F8F2\">(address)<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">&amp;key=<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">apiKey<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">`<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> data <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> JSON.<\/span><span style=\"color: #A6E22E\">parse<\/span><span style=\"color: #F8F8F2\">(response.<\/span><span style=\"color: #A6E22E\">getContentText<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For each address, a geocoding request is sent to the Google Maps API.<\/li>\n\n\n\n<li>The address is encoded using the <code>encodeURIComponent<\/code> function to safely include it in the URL.<\/li>\n\n\n\n<li>The API response is parsed in JSON format for further processing.<\/li>\n<\/ul>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Writing the Results<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"      if (data.status === &quot;OK&quot;) {\n        const location = data.results[0].geometry.location;\n        sheet.getRange(i + 2, 2).setValue(location.lat); \/\/ Write latitude to column B\n        sheet.getRange(i + 2, 3).setValue(location.lng); \/\/ Write longitude to column C\n      } else {\n        sheet.getRange(i + 2, 2).setValue(&quot;Error&quot;); \/\/ Handle errors\n        sheet.getRange(i + 2, 3).setValue(&quot;Error&quot;);\n      }\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (data.status <\/span><span style=\"color: #F92672\">===<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">&quot;OK&quot;<\/span><span style=\"color: #F8F8F2\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> location <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> data.results[<\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">].geometry.location;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(location.lat); <\/span><span style=\"color: #88846F\">\/\/ Write latitude to column B<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">3<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(location.lng); <\/span><span style=\"color: #88846F\">\/\/ Write longitude to column C<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      } <\/span><span style=\"color: #F92672\">else<\/span><span style=\"color: #F8F8F2\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Error&quot;<\/span><span style=\"color: #F8F8F2\">); <\/span><span style=\"color: #88846F\">\/\/ Handle errors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(i <\/span><span style=\"color: #F92672\">+<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #AE81FF\">3<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Error&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the response is successful (<code>status: \"OK\"<\/code>), the latitude and longitude are written to columns B and C, respectively.<\/li>\n\n\n\n<li>If an error occurs, &#8220;Error&#8221; is output in both columns B and C.<\/li>\n<\/ul>\n<\/dd>\n<\/dl>\n<\/div><\/details>\n<\/div>\n<\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\"><strong>Save the Script<\/strong><\/div><div class=\"swell-block-step__body\"><div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"1024\" height=\"465\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-68-1024x465.png\" alt=\"\" class=\"wp-image-17225\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-68-1024x465.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-68-300x136.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-68-768x349.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-68-1536x697.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-68.png 1586w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>After writing the script, save it with a name.<\/p>\n\n\n\n<p>(Example: <strong>&#8220;LatLng&#8221;<\/strong>)<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\">Run the Script<\/div><div class=\"swell-block-step__body\"><div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"1024\" height=\"465\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-69-1024x465.png\" alt=\"\" class=\"wp-image-17226\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-69-1024x465.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-69-300x136.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-69-768x349.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-69-1536x697.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-69.png 1586w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"u-mb-ctrl u-mb-40\">Run the script to calculate the latitude and longitude from the addresses in column A.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-big_icon_memo u-mb-ctrl u-mb-60\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>If you&#8217;re running the script for the first time, you need to authorize it.<\/p>\n\n\n\n<p><strong>Therefore, press &#8220;<strong>Review Permissions.<\/strong>&#8220;<\/strong><\/p>\n\n\n<div class=\"wp-block-image u-mb-ctrl u-mb-50\">\n<figure class=\"alignleft size-full\"><img decoding=\"async\" width=\"882\" height=\"345\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79.png\" alt=\"\" class=\"wp-image-15938\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79.png 882w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79-300x117.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79-768x300.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/figure>\n<\/div>\n\n\n<div class=\"swell-block-accordion\">\n<details class=\"swell-block-accordion__item\" data-swl-acc=\"wrapper\"><summary class=\"swell-block-accordion__title\" data-swl-acc=\"header\"><span class=\"swell-block-accordion__label\">Detailed Authorization Steps<\/span><span class=\"swell-block-accordion__icon c-switchIconBtn\" data-swl-acc=\"icon\" aria-hidden=\"true\" data-opened=\"false\"><i class=\"__icon--closed icon-caret-down\"><\/i><i class=\"__icon--opened icon-caret-up\"><\/i><\/span><\/summary><div class=\"swell-block-accordion__body\" data-swl-acc=\"body\">\n<p><strong>Press &#8220;Advanced.&#8221;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full u-mb-ctrl u-mb-50\"><img decoding=\"async\" width=\"1272\" height=\"688\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d.jpg\" alt=\"\" class=\"wp-image-15939\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d.jpg 1272w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d-300x162.jpg 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d-1024x554.jpg 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d-768x415.jpg 768w\" sizes=\"(max-width: 1272px) 100vw, 1272px\" \/><\/figure>\n\n\n\n\n\n\n\n<p><strong>Press &#8220;Go to Untitled project (Unsafe).&#8221;<\/strong><\/p>\n\n\n<div class=\"wp-block-image u-mb-ctrl u-mb-50\">\n<figure class=\"alignleft size-full\"><img decoding=\"async\" width=\"1305\" height=\"893\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9.jpg\" alt=\"\" class=\"wp-image-15940\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9.jpg 1305w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9-300x205.jpg 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9-1024x701.jpg 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9-768x526.jpg 768w\" sizes=\"(max-width: 1305px) 100vw, 1305px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>After that, press &#8220;Allow.&#8221;<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full is-resized\"><img decoding=\"async\" width=\"955\" height=\"543\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049.jpg\" alt=\"\" class=\"wp-image-15941\" style=\"width:566px;height:auto\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049.jpg 955w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049-300x171.jpg 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049-768x437.jpg 768w\" sizes=\"(max-width: 955px) 100vw, 955px\" \/><\/figure>\n<\/div>\n\n\n\n<\/div><\/details>\n<\/div>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\">Latitude and Longitude Output<\/div><div class=\"swell-block-step__body\">\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"407\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-71-1024x407.png\" alt=\"\" class=\"wp-image-17228\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-71-1024x407.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-71-300x119.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-71-768x305.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-71.png 1388w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"u-mb-ctrl u-mb-40\">Column B will display the latitude, and column C will display the longitude.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"613\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70-1024x613.png\" alt=\"\" class=\"wp-image-17227\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70-1024x613.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70-300x179.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70-768x459.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70-1536x919.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70-2048x1225.png 2048w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-70.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To verify, input the latitude and longitude into Google Maps, and the corresponding location will be displayed.<\/p>\n\n\n\n<p>For example:<br>Address: 1600 Amphitheatre Parkway, Mountain View, CA<br>Latitude: 37.4221534<br>Longitude: -122.0842385<\/p>\n<\/div><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading u-mb-ctrl u-mb-40\">Notes<\/h2>\n\n\n\n<dl class=\"swell-block-dl u-mb-ctrl u-mb-60\">\n<dt class=\"swell-block-dl__dt\"><strong>Address Accuracy<\/strong>:<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<p>If the input address is vague or inaccurate, the script may not return correct results. Ensure the address is as precise as possible.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Free Usage Tier<\/strong>:<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<p>Google Maps API offers a free usage tier of $200 per month, which typically covers regular usage without incurring charges.<\/p>\n<\/dd>\n<\/dl>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced: Creating a Custom Function<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"451\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-74-1024x451.png\" alt=\"\" class=\"wp-image-17231\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-74-1024x451.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-74-300x132.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-74-768x338.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-74.png 1394w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-border -border02 has-swl-pale-03-background-color has-background\"><strong>Get Latitude<\/strong>:<code>=INDEX(GEOCODE(A2), 1)<\/code><br><strong>Get Longitude<\/strong>:<code>=INDEX(GEOCODE(A2), 2)<\/code><\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-50\">You can use Google Apps Script to create a custom function that can be called directly in your spreadsheet.<\/p>\n\n\n\n<p>Add the following code to your Apps Script editor:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"function GEOCODE(address) {\n  if (!address) return [&quot;&quot;, &quot;&quot;]; \/\/ Return empty values if no address is provided\n\n  \/\/ Retrieve the API key from script properties\n  const apiKey = PropertiesService.getScriptProperties().getProperty(&quot;Maps_API_KEY&quot;);\n  \n  \/\/ Construct the Google Maps Geocoding API URL\n  const url = `https:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=${encodeURIComponent(address)}&amp;key=${apiKey}`;\n  \n  \/\/ Fetch the API response\n  const response = UrlFetchApp.fetch(url);\n  const data = JSON.parse(response.getContentText());\n  \n  \/\/ Check if the response status is OK and return latitude and longitude\n  if (data.status === &quot;OK&quot;) {\n    const location = data.results[0].geometry.location;\n    return [location.lat, location.lng];\n  }\n\n  \/\/ Return an error message if the response status is not OK\n  return [&quot;Error&quot;, &quot;Error&quot;];\n}\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">function<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">GEOCODE<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #FD971F; font-style: italic\">address<\/span><span style=\"color: #F8F8F2\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #F92672\">!<\/span><span style=\"color: #F8F8F2\">address) <\/span><span style=\"color: #F92672\">return<\/span><span style=\"color: #F8F8F2\"> [<\/span><span style=\"color: #E6DB74\">&quot;&quot;<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #E6DB74\">&quot;&quot;<\/span><span style=\"color: #F8F8F2\">]; <\/span><span style=\"color: #88846F\">\/\/ Return empty values if no address is provided<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Retrieve the API key from script properties<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> apiKey <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> PropertiesService.<\/span><span style=\"color: #A6E22E\">getScriptProperties<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getProperty<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Maps_API_KEY&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Construct the Google Maps Geocoding API URL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> url <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">`https:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #A6E22E\">encodeURIComponent<\/span><span style=\"color: #F8F8F2\">(address)<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">&amp;key=<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">apiKey<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">`<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Fetch the API response<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> response <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> UrlFetchApp.<\/span><span style=\"color: #A6E22E\">fetch<\/span><span style=\"color: #F8F8F2\">(url);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> data <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> JSON.<\/span><span style=\"color: #A6E22E\">parse<\/span><span style=\"color: #F8F8F2\">(response.<\/span><span style=\"color: #A6E22E\">getContentText<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Check if the response status is OK and return latitude and longitude<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (data.status <\/span><span style=\"color: #F92672\">===<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">&quot;OK&quot;<\/span><span style=\"color: #F8F8F2\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> location <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> data.results[<\/span><span style=\"color: #AE81FF\">0<\/span><span style=\"color: #F8F8F2\">].geometry.location;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">return<\/span><span style=\"color: #F8F8F2\"> [location.lat, location.lng];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Return an error message if the response status is not OK<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">return<\/span><span style=\"color: #F8F8F2\"> [<\/span><span style=\"color: #E6DB74\">&quot;Error&quot;<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #E6DB74\">&quot;Error&quot;<\/span><span style=\"color: #F8F8F2\">];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Click the &#8220;\u25b6 Run&#8221; button in the top menu to execute the script once.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-40\">Then, follow the same steps as before to grant the necessary permissions.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>How to Use the Custom Function<\/strong><\/h4>\n\n\n\n<p>Enter the following formulas into the cells:<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-10\"><strong>To get the latitude (Column B)<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro u-mb-ctrl u-mb-40\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"=INDEX(GEOCODE(A2), 1)\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F92672\">=<\/span><span style=\"color: #A6E22E\">INDEX<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #A6E22E\">GEOCODE<\/span><span style=\"color: #F8F8F2\">(A2), <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"u-mb-ctrl u-mb-10\"><strong>To get the longitude (Column C)<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro u-mb-ctrl u-mb-60\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"=INDEX(GEOCODE(A2), 2)\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F92672\">=<\/span><span style=\"color: #A6E22E\">INDEX<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #A6E22E\">GEOCODE<\/span><span style=\"color: #F8F8F2\">(A2), <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading u-mb-ctrl u-mb-30\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>By using Google Apps Script, you can easily retrieve latitude and longitude from addresses directly within Google Sheets.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-40\">This method is ideal for batch processing address data or automating location-based tasks. Give it a try to enhance your workflow!<\/p>\n\n\n<div class=\"swell-block-postLink u-mb-ctrl u-mb-30\">\t\t\t<div class=\"p-blogCard -internal\" data-type=\"type1\" data-onclick=\"clickLink\">\n\t\t\t\t<div class=\"p-blogCard__inner\">\n\t\t\t\t\t<span class=\"p-blogCard__caption\">\u3042\u308f\u305b\u3066\u8aad\u307f\u305f\u3044<\/span>\n\t\t\t\t\t<div class=\"p-blogCard__thumb c-postThumb\"><figure class=\"c-postThumb__figure\"><img decoding=\"async\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/c79a346b2ddab646e17282bf7501e204-300x158.png\" alt=\"\" class=\"c-postThumb__img u-obf-cover\" width=\"320\" height=\"180\"><\/figure><\/div>\t\t\t\t\t<div class=\"p-blogCard__body\">\n\t\t\t\t\t\t<a class=\"p-blogCard__title\" href=\"https:\/\/84office.jp\/en\/googlesheets-map-linkage\/\">Google Sheets + Google Maps: Automatically Generate Map Links from Addresses<\/a>\n\t\t\t\t\t\t<span class=\"p-blogCard__excerpt\">Google Maps links are useful, but does it take a lot of time to display each one if there are many places you want to check? In particular, if you have addre&#8230;<\/span>\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n\n<div class=\"p-postListWrap u-mb-ctrl u-mb-30\"><ul class=\"p-postList -type-simple\"><li class=\"p-postList__item\">\n\t<a href=\"https:\/\/84office.jp\/en\/google-sheets-qr-code-chrome-extension\/\" class=\"p-postList__link\">\n\t\t<div class=\"p-postList__body\">\n\t\t\t<div class=\"p-postList__meta\">\n\t\t\t\t<div class=\"p-postList__times c-postTimes u-thin\">\n\t<time class=\"c-postTimes__posted icon-posted\" datetime=\"2024-12-25\" aria-label=\"\u516c\u958b\u65e5\">2024\u5e7412\u670825\u65e5<\/time><\/div>\n\t\t<span class=\"p-postList__cat u-thin icon-folder\" data-cat-id=\"12\">Google Sheets<\/span>\n\t\t\t\t<\/div>\n\t\t\t<h2 class=\"p-postList__title\">How to Create QR Codes in Google Sheets Using a Chrome Extension<\/h2>\t\t<\/div>\n\t<\/a>\n<\/li>\n<li class=\"p-postList__item\">\n\t<a href=\"https:\/\/84office.jp\/en\/get-youtube-data-api\/\" class=\"p-postList__link\">\n\t\t<div class=\"p-postList__body\">\n\t\t\t<div class=\"p-postList__meta\">\n\t\t\t\t<div class=\"p-postList__times c-postTimes u-thin\">\n\t<time class=\"c-postTimes__posted icon-posted\" datetime=\"2024-12-18\" aria-label=\"\u516c\u958b\u65e5\">2024\u5e7412\u670818\u65e5<\/time><\/div>\n\t\t<span class=\"p-postList__cat u-thin icon-folder\" data-cat-id=\"12\">Google Sheets<\/span>\n\t\t\t\t<\/div>\n\t\t\t<h2 class=\"p-postList__title\">YouTube API Key Setup: Export and Manage Video Data in Google Sheets<\/h2>\t\t<\/div>\n\t<\/a>\n<\/li>\n<li class=\"p-postList__item\">\n\t<a href=\"https:\/\/84office.jp\/en\/google-calendar-free-time-extraction\/\" class=\"p-postList__link\">\n\t\t<div class=\"p-postList__body\">\n\t\t\t<div class=\"p-postList__meta\">\n\t\t\t\t<div class=\"p-postList__times c-postTimes u-thin\">\n\t<time class=\"c-postTimes__posted icon-posted\" datetime=\"2025-07-24\" aria-label=\"\u516c\u958b\u65e5\">2025\u5e747\u670824\u65e5<\/time><\/div>\n\t\t<span class=\"p-postList__cat u-thin icon-folder\" data-cat-id=\"12\">Google Sheets<\/span>\n\t\t\t\t<\/div>\n\t\t\t<h2 class=\"p-postList__title\">How to Find Common Free Time in Google Calendar: Manage Shared Schedules with Google Apps Script<\/h2>\t\t<\/div>\n\t<\/a>\n<\/li>\n<\/ul><\/div>\n\n\n<p class=\"is-style-emboss_box has-swl-pale-02-background-color has-background\">Our company offers support for improving work efficiency through the use of Google Apps Script. <br>If you need assistance with Google Apps Script customization or error resolution, please feel free to contact us. <br>We are fully committed to supporting your business improvements.<br><br><a href=\"https:\/\/84office.jp\/contact\/\">Contact us here<br><\/a><\/p>\n\n\n\n<script src=\"https:\/\/codoc.jp\/js\/cms.js\" data-css=\"rainbow\" data-usercode=\"pQLZofrBiA\" charset=\"UTF-8\" defer><\/script>\n <div id=\"codoc-entry-9lNr9PuMXQ\" class=\"codoc-entries\" data-without-body=\"1\" data-support-button-text=\"Support with a Tip\" data-support-message=\"We will keep offering tools and information to boost work efficiency. Your support helps us provide even better content.\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the previous article, we introduced how to obtain an API key for using the Google Maps API. In this article [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":17233,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","_locale":"en_US","_original_post":"https:\/\/84office.jp\/?p=16710","footnotes":""},"categories":[12],"tags":[],"class_list":["post-17221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-12","en-US"],"_links":{"self":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts\/17221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/comments?post=17221"}],"version-history":[{"count":2,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts\/17221\/revisions"}],"predecessor-version":[{"id":17232,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts\/17221\/revisions\/17232"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/media\/17233"}],"wp:attachment":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/media?parent=17221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/categories?post=17221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/tags?post=17221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}