当前位置:首页 > 未分类 > 正文内容

How to Link Postal Addresses to Google Maps in Google Sheets

ceacer3周前 (05-02)未分类7874

Bob Canning writes: I have a Google Spreadsheet with postal addresses in column A. Each week, a real estate agent copies a section of those addresses to a “upcoming tour” tab on our website. The tab is shared with other real estate agents so they can see the addresses in the order they will be viewed on the tour. I would like to make all of the addresses clickable so that people can easily navigate to the next location on the tour. Is this possible?

Google Maps Links in Google Sheets

Make Addresses Clickable in Google Sheets

We can use custom functions in Google Sheets with the built-in HYPERLINK function to make any location clickable in the spreadsheet. And unlike other Google Maps functions, this approach doesn’t make any Maps API calls so there’s no restriction on the number of links that you can generate in a sheet.

Assuming that your postal addresses are in column A from row 2 to row 11, go to column B and paste the custom function. The first parameter refers to the cell, or range of cells, that contain the location that needs to be hyperlinked. You can set the second ‘satellite’ parameter to TRUE if you would like to link the map to the aerial view instead of the regular map view of Google Maps.

=GOOGLEMAPSLINK(A2:A11, FALSE)

The Google Maps Link function is obviously not part of Google Sheets but we can easily integrate it with the help of Google Apps Script.

Generate Maps URL with Apps Script

Open your Google Sheets spreadsheet. Click on “Extensions” in the top menu, then select “Apps Script.” In the Apps Script editor that opens, replace any existing code with the following function:

/**
 * Generate a Google Maps Link for any address
 *
 * @param {string} address - The postal address
 * @param {boolean} satellite - Show aerial view (TRUE or FALSE)
 * @returns {string} The Google Maps URL
 * @customFunction
 */

function GOOGLEMAPSLINK(address, satellite) {
  function createLink(query) {
    const baseUrl = 'https://maps.google.com/?q=' + encodeURIComponent(query);
    const mapsUrl = baseUrl + (satellite ? '&t=k' : '');
    return mapsUrl;
  }

  return Array.isArray(address) ? address.map(createLink) : createLink(address);
}

The GOOGLEMAPSLINK function can generate map links for addresses in a single cell as well as a range of cells.

We can also add another column to the sheet that will create a clickable link with the address text. Paste the following ArrayFormula function in cell C1. See demo sheet.

=ArrayFormula(HYPERLINK(B2:B11,A2:A11))

Clickable Address in Google Sheets

The hyperlinked postal addresses can also be copied and pasted directly into Word, or any rich text editor, including HTML Mail for Gmail.

相关文章

How Teachers can Email Parents of Students from Google Forms

How Teachers can Email Parents of Students from Google Forms

A school provides email accounts for students that are enrolled in high school. The school has publ...

How to Make Personalized Place Cards with Guest Names

How to Make Personalized Place Cards with Guest Names

Whether it is a wedding party or a business conference, those tent-shaped place cards are ideal for...

How to Get the Last Row in Google Sheets when using ArrayFormula

How to Get the Last Row in Google Sheets when using ArrayFormula

Here we have an employee list spreadsheet with a column named Employee Name and a column named Emplo...

How to Extract URLs from HYPERLINK Function in Google Sheets

The HYPERLINK formula of Google Sheets lets you insert hyperlinks into your spreadsheets. The functi...

How to Request Stripe Payments with Google Sheets

How to Request Stripe Payments with Google Sheets

Stripe now offers a Payment Links API to help you programmatically generate payment links in bulk fo...