In this codelab, you'll make an app that allows you to choose from a list of addresses and view the location on Google Maps.
Create a new project called
MapIt
(no spaces).
The starting screen for this app will be the Map It logo. When the user clicks on the logo, the app will move onto the next screen.
Add a Canvas component and set the Background Image to app_logo.png.
We will need to create a new screen called MainScreen
for the main app functionality.
Design your user interface so that at a minimum it has the following elements:
Remember to give your components meaningful names!
This next step will allow you to switch from the starter screen to the main screen by clicking anywhere on the logo.
Screen1
(the starter screen).We use lists all the time in real life. Think of grocery lists, top songs lists, todo lists, etc. Lists are also super useful when programming.
In this step, we will use a list to keep track of different locations that the user can select.
locationList
.make a list
block (from the "Lists" drawer) to
create a list. By default, the list will only contain two items, but
you can add more space to your list by clicking on the small gear
icon in the top left corner of the block. Drag as many
item
blocks as you need into the list
block on the right.when MainScreen.Initialize
event handler to
populate the ListPicker with the locations in
locationsList
. Hint: Use the set
ListPicker.Elements
block.when ListPicker.AfterPicking
event handler to
set the text of the SelectedLocationLabel to
ListPicker.Selection
. What do you think this does?
If you restart your app, you will notice that your selected location is not saved. You have to click on the ListPicker again to reselect your desired location.
Luckily for you, the TinyDB component allows you to save your selected location so that the next time you open your app, the location you selected will still be selected!
First, let's talk about what a database is. You can think of it as a way to store information in an organized manner. The data stored on a TinyDB component is available each time the app is run.
We need to label the data we want to store using a tag.
In the example below, we use TinyDB to store someone's favorite
singer using the tag favoriteSinger
.
To retrieve data we need to use the same tag to ask TinyDB
for the information we want. There is a possibility that the TinyDB
does not have any information stored for that tag, so we need to
specify what value to return for that scenario. It's okay to use an
empty text string for valueIfTagNotThere
, but in the
example below, we return Beyonce
if the TinyDB does not
have any information under the tag favoriteSinger
.
Display the previously selected location, even if the user restarts the app. Hint: Use the TinyDB component.
When the user clicks on the "View Location on Map" button, we want to show the location using Google Maps.
showMap
.call Notifier.ShowMessageDialog
block to show a message (e.g. "No location has been selected yet!").
Otherwise, if the user has selected a location, then call the
showMap
method you made in the previous step.
The
Activity Starter component is useful when we want to open
other applications on the phone from our own app. There are two
properties of the Activity Starter that we need to set: the Action
property and the DataUri
property.
Fill in your showMap
method as follows.
You have used App Inventor to create an app that shows locations on a map.