Activity 3-3

November 12, 2015

Task 1: Open Google Earth

Google Earth is a mapping application that can load in data files that look like XML (they are "KML") and use that data to add locations, marks, or other pieces of information to the map visualization. Now that we know how to output text files using a Python code, imagine creating a KML file as output. Marker locations or visual properties, like the size or color of pins in the map, could be chosen based on some logic or analysis in your program. Then, you could open the KML in Google Earth and use the visualization to evaluate a claim about the data.

First, you'll need to get Google Earth up and running.

  1. Open Google Earth on your computer. If Google Earth is not installed, you can download it for free.
  2. Try rotating, zooming, and adding a pin to the map.

Task 2: Edit Properties of the Map File

Download CIT.kml. In Google Earth, choose File > Open... from the menu bar and select the KML file you downloaded.

  1. Locate the pins on the map. Click on them to read the name and description.
  2. In Notepad (or TextEdit on a Mac), open CIT.kml. Can you locate the properties of marks with this file?
  3. Edit some properties, including the pin scale, color, name, and description. Add new marks if you like. When you're finished, save this file and open it again in Google Earth. How did the map change?

Task 3: Print More Than just Country Names

Download gecoords.py and change the printCountry function to print city, state, and country. Look for the descriptors "locality", "administrative_area_level_1", and "country". Test your functions with the following locations:

  1. '41.8236,-71.4222'
  2. '-15.7939,-47.8828'
  3. '51.5072,0.1275'

Print the state by its abbreviated name (e.g. "RI") if available.

Can you tell why we only print city and country for location #3? Hint: Construct the JSON request URL by hand (refer to slides for notation), and examine the contents.

Why do you think that our function first prints city, then state, then country, regardless of the order on the additional if statements that you add into the for loop? Does that have to do with the JSON response structure?