Pizza Delivery With Google Sheets

Published on February 20, 2022

Introduction

In this guide, we will make a pizza delivery app with Google Sheets as the database. We will get the latitude, longitude, timestamp, pizza type and drink type from the user.

To read about how to post data to Google Sheets, click here. Thank you METRIC RAT AI2!

🏷️ Tags: #tutorials-and-guides, #apps-script, #google

A. Setting up a project.

  1. Create a project, give it a suitable name.

  2. Add a button that says 'Order pizza', a label that says 'Co-ordinates: 0, 0' and two new spinners and a HorizontalArrangement.

  3. Arrange the components (see the screenshot below/right).

  4. Add a LocationSensor (Sensors), a Clock (Sensors) and a Web component.

  5. Set the TimeInterval for the LocationSensor to 1000 (= 1 second).

B. Setting up a Google Sheet.

  1. Open https://sheets.new.

  2. Rename the new spreadsheet to 'Pizza Delivery Sheet'.

  3. Click on the Share button. Reset the settings to that anyone on the web can edit.

  4. Set the interface of your spreadsheet to something like this. You must put everything in the correct order. Make sure the sheet name is Sheet1.

5. Copy your spreadsheet link and paste it in a new tab (do not press Enter). Your link should be in the following format (URL modified, this is a fake URL). The text in blue is your file ID. Copy the file ID of your spreadsheet link and paste it in Notepad/Google Docs/somewhere that you can find it.

https://docs.google.com/spreadsheets/d/1yWLGUVZwChViKwegAyGmF2akkhimTNqYQoxIptsX0XA/edit?usp=sharing

C. Setting up Google Apps Script

  1. Open Google Drive. Click on New > More> Google Apps Script. Your project will take some time to load.

  2. Rename your project to PizzaDelivery.

  3. Delete all of the text in the code and replace ot with this. Replace <FILE ID HERE> with your spreadsheet ID.

function doPost(e) {

var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/<FILE ID HERE>/edit#gid=0");

var sheet = ss.getSheetByName("Sheet1");

var timestamp = e.parameter.timestamp ;

var latitude = e.parameter.latitude ;

var longitude = e.parameter.longitude ;

var pizza = e.parameter.pizza ;

var drink = e.parameter.drink ;

sheet.appendRow([timestamp, latitude, longitude, pizza, drink]);

}

4. Deploy your web app and copy the deployment URL into a text editor that you can get it later. Click here to read how to deploy a web app.

D. App Inventor Blocks.

For convenience, the button 'Order pizza' has been renamed to 'OrderPizzaButton'.

  • We use the LocationSensor to find the user's latitude and longitude. When the location changes, we will show the changes on Label1. Make sure you have location permission.

  • Paste the deployment URL into the global variable deploymentUrl.

  • We have a list of pizzas and drinks in pizzaList and drinksList. You can add more items.

  • Spinner1 is used for pizzas, and Spinner2 is for drinks. We set the default selections at the start of the program. The selection cannot be empty when we post the text.

  • We use the Clock to find out the current date and time.

  • When the user clicks on the OrderPizzaButton, we post the text to the Google Sheet.

Downloads

Tests

Tested successfully on the AI Companion on Xiaomi 5G 11 NE Lite.