
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a new Google Sheet and enter a street address
/ 50
Run the Google Sheets, Maps, and Gmail app
/ 50
In this lab, you are introduced to one of the easiest ways to write code that accesses Google developer technologies, all by leveraging one of the mainstream web development languages, JavaScript. Using Google Apps Script, you write code to extract an address sitting in a cell in a Google Sheet, generate a Google Map based on that address, and send a link to the map to yourself or a friend using Gmail. The best part? It really takes only 4 lines of code!
The following experience would enhance your learning experience:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
When you are ready, click Start Lab.
The Lab Details pane appears with the temporary credentials that you must use to sign into Gmail for this lab.
If you need to pay for the lab, a pop-up opens for you to select your payment method.
Click Open Google Sheets.
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Open the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog:
Click Next.
Copy the Password below and paste it into the Welcome dialog:
Click Next.
Accept all terms and conditions as prompted.
Google Sheets opens and you are signed in to your Student Google Account.
Google Apps Script has a development environment that may be different from what you're used to. With Apps Script, you:
Apps Script applications come in one of two forms:
Bound and Standalone apps can also be published to expose more broadly:
Your first Apps Script app should be bound to a Google Sheet. Time to create a new spreadsheet!
Enter a street address in a new Google Sheet by following these instructions:
That's all you have to do in the Sheet. Now you're ready to enter the editor and write some code!
Click Check my progress to verify that you've performed the above task.
Apps Script provides a code editor you use to create the Sheets bound script.
Apps Script opens. Notice the code editor window on the right:
A default function named myFunction()
is automatically created for you, and in the editor. That's it... you're now ready to write your application.
Code.gs
provides "template" code and doesn't do much. Copy the code below and paste it in the editor window to replace the template code. Then update <YOUR_EMAIL>
with lab provided user email:You did it. Not counting the optional annotation, you just created sendMap()
, a 4 line app.
Remember to replace <YOUR_EMAIL>
with the user email provided by this lab so you can check for email messages during this lab.
Did you notice when you replaced the code in the editor, a red circle showed up to the left of the file name?
That means you've edited the file which now needs to be saved. You'll see it every time you have an unsaved edit.
Alternatively, you can CTRL+S (PCs, Linux) or Command+S (Mac). You must name your project before you can proceed.
To run the app you created:
sendMap()
, select the function to run as sendMap:sendMap()
function.Apps Script manages the authorization code, so you don't have to write it. App users, however, still need to grant permission to the script to access your Sheet and be able to send email through Gmail on your behalf. The first auth dialog looks like this:
After you grant permission, the script runs to completion.
sendMap
listed. Click View Dashboard if prompted.Click the Open Gmail button shown on the left side lab panel.
In the Choose and account dialog, enter your student username and click Next.
Enter the lab provided Password and click Next.
Click Accept to accept the terms.
You should now be in Gmail, looking at your Inbox. You should find a message with Subject "Map" and a message body that looks like this:
Click Check my progress to verify that you've performed the above task.
Just think about it... four lines of code that access three different Google products in a meaningful way, even though it's not a complete application by itself. Even if you're unfamiliar with JavaScript or Apps Script, the code should be readable enough to give you a rough idea how it works, and perhaps what Apps Script can accomplish for you.
This section reviews the code in more detail.
Since this application is short, there's no overall code structure to discuss. Instead,this section reviews each line of this app, which touches three different Google products!
This is a normal JavaScript function declaration for sendMap()
:
The first line of code calls the Spreadsheet Service accessible from Apps Script via the SpreadsheetApp object. The returned sheet is assigned to a variable of the same name.
The getActiveSheet() method does exactly what it says it does—it returns a "handle" to the current sheet that is active in the user interface (UI):
With the sheet
object, reference the cell range (of a single cell) in A1 notation with getRange(). A "range" is a group of cells, including just a single one like yours... cell A1
, the one you entered the address in.
Now fetch what's inside that range of cells with the getValue() call, and assigned it to the address variable upon return. Try adding more addresses and reading from different cells.
The 3rd line connects to the Google Maps Service via the Maps object. As soon as you have access to the Maps Service, request that a new static map be created via newStaticMap().
You can then put a "pin" dropped onto the address you pulled from the Sheet by using the addMarker() method:
The last line uses the Mail Service (via the GmailApp object), calling its sendEmail() method, to send the email which includes both the text "See below." and the map image as an attachment:
You used the Google Apps Script to write code that accesses Google developer technologies to extract an address in Google Sheets, generate a Google Map based on that address, and sends the map to an email recipient.
The code featured in this lab is also available at its GitHub repo at GitHub.com/googlecodelabs/apps-script-intro. (This lab aims to stay in-sync with the repo.) Below are additional resources to help you dig deeper into the material covered in this lab as well as explore other ways of accessing Google developer tools programmatically.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated November 05, 2024
Lab Last Tested November 05, 2023
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one