Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
9.10. My Directions Tutorial (Optional)¶
Time Estimate: 45 minutes
My Directions This tutorial shows how to use the Location Sensor
in combination with Google Maps to display directions from the user’s
current location to a selected destination.
(Teacher Tube version)
Objectives: In this lesson you will learn to :
Building the MyDirections App
To get started, open App Inventor with the My Directions Template in a separate tab and follow along with these tutorials.
You can either click on the thumbnails to view the video or click here to read the tutorial.
9.10.2. Enhancements: Creative Projects¶There are a number of enhancements you could implement to improve this app.
- In its current form, the destination addresses are created by the programmer. Add a Textbox and a Button to the UI to enable the user to input their own destination addresses. Addresses entered by the user should be added to the destinations list. This will make it possible to share the app with friends.
- Improve the presentation of the search results by using or modifying one or more additional API arguments in the Map’s URL. Here is a complete list of the Maps API arguments.
- Advanced: Add a TinyDb to the app so that the user’s destinations will persist. Addresses saved in the TinyDb will be there the next time the app is used.
HINT 1: Lists (as well as numbers and strings) can be stored in a TinyDb. So you can store the entire destinations list as one element. Determine when and how to store the destinations. Then, determine when and how to retrieve the destinations.
HINT 2: The destinations should be retrieved from the TinyDb when the app is initialized. Here’s how:
NOTE: This can be tricky to understand. The first time the app is run, there definitely won’t be any ‘addresses’ stored in the TinyDb. You can specify how to handle the empty data situation with the valueIfTagNotThere parameter. In the example, we set global destinations to a default fixed list so the first time the app runs it will have some sample destinations You could also put a create empty list in valueIfTagNotThere if you wanted the destinations list empty to start. This problem won’t arise once the user has stored some addresses in the TinyDb.
It is important to explore with App Inventor and become accustomed to programming without explicit instructions. So try out the challenges listed above and see how far you can get.
If you get stuck -- or, after you've finished, to compare your solutions with ours -- check out the solutions video.
9.10.5. Still Curious¶
In this lesson you used the Google Maps Application Programming Interface (API), an abstraction that lets you specify commands to the Google Maps application. This is a nice example of cloud computing: Google Maps is the cloud-based application that programmers can incorporated into their apps by learning the API. This is also a nice example of how a program -- in this case a mobile app -- can leverage functionality that professional programmers have developed.
This example is not an isolated case. YouTube, Flickr, Twitter, and Amazon all provide APIs to use at least part of their services.
9.10.6. Reflection: For Your Portfolio¶Create a new page named My Directions under the Reflections category of your portfolio and write brief answers to the following questions:
- What are the advantages of having a location aware app? What are the disadvantages?
- If you added any enhancements, post the screenshots to your portfolio and explain how you implemented the enhancements.