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.
Download CIT.kml
. In Google Earth, choose File > Open... from the menu bar and select the KML file you downloaded.
CIT.kml
. Can you locate the properties of marks with this file? 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:
'41.8236,-71.4222'
'-15.7939,-47.8828'
'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?