9.10. My Directions Tutorial (Optional)

Time Estimate: 45 minutes

9.10.1. Preview

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 :

  • create an app that
    • uses the Global Positioning System(GPS) to obtain the user's current location,
    • uses the Google Maps Application Programming Interface (API) to obtain directions from the user's current location to a destination address;
  • appreciate that Google Maps API is an abstraction that allows apps to leverage existing functionality;
  • obtain some additional experience working with lists and TinyDB to save user-generated information persistently.

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.
  1. 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.
  2. 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.
  3. 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. 
    Screen Shot 2014-08-05 at 3.27.37 PM.png

    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.

9.10.3. Solutions

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.4. Self-Check

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:
  1. What are the advantages of having a location aware app? What are the disadvantages?
  2. If you added any enhancements, post the screenshots to your portfolio and explain how you implemented the enhancements.