Getting the User’s Location
If you want to know where the accessible places near you are, you are going to need users to add their locations to your app. Luckily, App Inventor has a LocationSensor component that detects a user’s location.
- On the “AddPlace” screen, drag a LocationSensor from Sensors onto your app.
You’re now going to get the user’s location and put it into the TextBox.
- Switch over to the Blocks view and drag two
when Button.Clickblocks onto the screen.
Renaming components
I like giving my components identifiable names.
-
In the Designer view, click on the component. At the bottom of the Components section, click Rename.
-
I called my Buttons “currentLocation” and “Save”.
-
Drag a
set TextBox.Textblock onto the screen and put it in your “Current Location” Button. -
Now drag a
LocationSensor.CurrentAddressblock out and attach it to theset TextBox.Textblock.

Great! Now when you click on “GetLocation”, the TextBox’s text will be set to your current address from the LocationSensor.
You need to be careful though: it’s a good idea to check that there is always an address in the TextBox before adding a new place! You need to validate the input.
-
Drag out an
if, then, elseblock, and put it into thewhen Save.Clickblock. -
Now you need to make the
ifcondition check if the TextBox has text in it. Drag out anis emptyblock, and attach it to aTextBox.textblock. -
OK, now you can check whether the TextBox is empty, but you want to check if it is not empty. To do this, get a
notblock out and put it before theis emptyblock.

One last thing: you need to tell the user that the TextBox is empty.
-
Switch over to the Designer view and drag a Label into the app. Give it a warning message and set the text color to red. Finally, uncheck the Visible checkbox.
-
You’ll want to show this label for a second, so you are going to need a Clock. Drag one out from Sensors — it will appear with the other non-visible components below the app screen.
-
Uncheck the clock’s TimerEnabled checkbox so it doesn’t fire right away!
-
Back in the Blocks view, drag a
set Label.Visibleand aset Clock.TimerEnabledblock out and attach both of them totrueblocks. Then put both in theelsestatement.

Nearly there! Now, if there is no text in the TextBox, your warning label will become visible and your clock will be enabled. You just need to make the label invisible again after about a second, so the user doesn’t have to keep looking at it.
- Take out a
when Clock.Timerblock and duplicate the two blocks you just made. Changetruetofalseand put duplicate blocks inside thewhen Clock.Timerblock.
