Geo Location

This assignment involves writing a simple class that is a variation of another class. The CS education community has struggled to find simple class examples that don't seem contrived or confusing. The most successful examples involve some form of scaffolding where the instructor provides a lot of supporting code. This assignment also involves scaffolding, but the interface is very simple. The code calls a method that accesses the Google Maps API to get information about a location given its coordinates (latitude and longitude).

Metadata

Summary Students practice being a client of a class for storing location information (latitude and longitude) and then write a variation of the class that stores extra information about a place of interest (name, address, and tags)
Topics
classes, constructors, fields, acting as the client of a class
Audience
Early (possible first) object assignment in a CS 1 class
Difficulty
Easy.
Strengths
Assignment is compelling because of the access to the Google Maps API and the two classes involved don't seem contrived or trivial. Many possible extensions.
Weaknesses
Short assignment.
Dependencies
Students need to know about methods, fields, and constructors. We use it in an objects-late course, but it could also be used in an objects-early course.
Variants
Crowdsourcing for location data, analyzing location data (e.g., looking for duplicate entries), many possible applications of mapping and distance computations.

Details

Students are shown the implementation of a GeoLocation class that keeps track of information about a location. Students intuitively understand that a location involves two pieces of information: a latitude and a longitude. It also has the nice property that these values are often expressed in two different ways: as three integers (hours, minutes, seconds) and as a single real number, which means that it makes sense to have two different constructors. It also has a nontrivial bit of behavior that you would not want to make others implement. Instead of something like the boring but classic Fahrenheit to Centigrade conversion, this class includes a method that finds the distance between two locations on Earth, which is not a simple calculation.

In the assignment, students first practice being a client of the GeoLocation class and then they write a variation of the class that keeps track of additional information about the location (it's name, address, and associated tags). Our observation is that students make many classic mistakes as they learn about objects in this assignment. For example, instead of storing their own GeoLocation object that computes the distance between two locations, they often copy the code from the GeoLocation class. That kind of confusion is useful to clear up early so that we can point out that one object often delegates some task to another object to complete.

The nifty part is the ability to access the Google Maps API. This makes the assignment more compelling. It also allows for many extensions to the basic assignment. For example, we wanted to have a large amount of data of places of interest near the University of Washington. This wasn't easy to get directly from Google, so we created our own through crowdsourcing. Each student submitted entries for a massive data file that we compiled.

I demonstrate in lecture that when the students complete their implementation of PlaceInformation, they can play with a DistanceFinder program that allows them to find out how far apart two locations are. For example, in the following log, we find out the distance between our classroom in Kane Hall and the Space Needle (user input in bold):

        This program finds the distance between two
        places using Google Maps data.
        
        first location? uw kane
        found at Kane Hall (latitude: 47.6566302, longitude: -122.3091536)
        second location? space needle
        found at Space Needle (latitude: 47.6205063, longitude: -122.3492774)
        3.121 miles apart
        
        Place # 1
            name    : Kane Hall
            address : Kane Hall, University of Washington, 4069 Spokane Lane, Seattle, WA 98105, USA
            tags    : university, point_of_interest, establishment
            location: latitude: 47.6566302, longitude: -122.3091536
        
        Place # 2
            name    : Space Needle
            address : Space Needle, 400 Broad Street, Seattle, WA 98109, USA
            tags    : point_of_interest, establishment
            location: latitude: 47.6205063, longitude: -122.3492774
It can be fun to generate silly results as well, like finding the distance between good and evil (not as far apart as you might imagine):
        This program finds the distance between two
        places using Google Maps data.
        
        first location? good
        found at Good (latitude: 41.422267, longitude: -76.835156)
        second location? evil
        found at Evil Avenue (latitude: 38.5413137, longitude: -89.8887517)
        719.176 miles apart
        
        Place # 1
            name    : Good
            address : Good, Trout Run, PA 17771, USA
            tags    : route
            location: latitude: 41.422267, longitude: -76.835156
        
        Place # 2
            name    : Evil Avenue
            address : Evil Avenue, Belleville, IL 62221, USA
            tags    : route
            location: latitude: 38.5413137, longitude: -89.8887517

Being able to show something fun they will be able to do once they complete an assignment can be highly motivating.

The final benefit of this assignment is that it gets students talking about all sorts of interesting topics:

Resources

We make the following resources available initially to students so that they can complete their version of PlaceInformation:

Once they have completed PlaceInformation, they can download the following client programs and data file to have some fun with their new class:

Below are a few other relevant links that we make available to students:

Below are links to sample solutions to the assigned classes. It requires the user/password combination that Stuart Reges often uses for his materials (you can request it by emailing Stuart).