The purpose of this lab is to demonstrate your knowledge of using a third party API to retrieve data, and process the data in a JSON format to extract the information that you need. You will also demonstrate your knowledge of putting together a simple GUI to display results.
Open API (Application Programming Interface) allows programmers/developers to access proprietary software applications and web services. This allows programmers to access backend data from other organizations. Some popular open API's include Twitter, Facebook, Google, and LinkedIn. Anytime you are able to log into a website using your credentials for another site such as Facebook, LinkedIn, or Twitter, that site is using an open API.
While open API's mean they are free to use, there are often restrictions to their use, like approval of a developer's account with Twitter. MapQuest is a company that provides online services related to maps. For our project, we will use the MapQuest OpenAPI, not because it's necessarily better than, say, Google Maps, but because it is easier to get started with access to interesting information.
You will write a class, MapQuest, that will have a constructor and four methods: totalDistance, totalTime, directions, and pointOfInterest.
In addition to your MapQuest class, you will also create a GUI that will display the results of your pointOfInterest method. Your GUI should have
For our project you will be using three API's provided by MapQuest, Open Directions API MapQuest Geocoding API
, MapQuest Place Search API , andYou should refer to the documentation and be familiar with it, although knowing everything in the documentation is unnecessary for this assignment.
Creating an account and getting an API Key
Before you can make use of the API, you'll need to obtain your own API Key. Do not share your API Key with other students! You'll only need to do this once, and you'll be able to use your API Key for all of your work on this project once it's been created. Obtaining the API Key is free for non-commercial uses like ours.
After you've completed this process, your MapQuest API Key will have been created, though it should be noted that it might take a little bit of time for it to become active, so don't panic if you're not able to use it right away.
Testing Your Key
Wait a little while after creating your API Key, then it's time to test that it's working. Open your favorite web browser; enter a URL in the following format into the browser's address bar and press Enter, replacing APIKEY with the Consumer Key part of the API key that you created in the previous step.
http://open.mapquestapi.com/directions/v2/route?key=APIKEY&from=Irvine%2CCA&to=Los+Angeles%2CCA
If successful, you should receive a result that looks roughly like this (though you'll get a lot more output than this):
{"route":{"hasTollRoad":false,"computedWaypoints":[],"fuelUsed":1.93,"hasUnpaved":false,"hasHighway":true,"realTime":-1, "boundingBox":{"ul":{"lng":-118.244476,"lat":34.057094},"lr":{"lng":-117.794593,"lat":33.6847}},"distance":40.675,"time":2518, "locationSequence":[0,1],"hasSeasonalClosure":false,"sessionId":"545ca8d0-03c3-001e-02b7-7cb8-00163edfa317", "locations":[{"latLng":{"lng":-117.825982,"lat":33.685697},"adminArea4":"Orange County","adminArea5Type":"City", "adminArea4Type":"County","adminArea5":"Irvine","street":"","adminArea1":"US","adminArea3":"CA","type":"s", "displayLatLng":{"lng":-117.825981,"lat":33.685695},"linkId":44589954,"postalCode":"","sideOfStreet":"N", "dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"CITY","geocodeQualityCode":"A5XCX","adminArea3Type":"State"},
Reading your JSON results
Because there is so much data, the JSON results can be difficult to read, or to find exactly what you are looking for when you're given the raw data. I recommend printing your JSON results to the console, and copy and pasting the results into a JSON viewer, like this one.
You can visualize the data in key/value pairs, and determine which key/values are needed.Outside Resources
Because the Open MapQuest APIs are fairly well-known online services, it is entirely possible that you would find Python modules online that have already been written and that know how to communicate with it. However, you are not permitted to download these and submit them as your own, in whole or in part, and you are not permitted to use them as any kind of basis for your own work. While you can use the Python standard library, you otherwise are expected to write this program entirely on your own.
There may be a discrepancy between distances, which is a result of how many queries you ran. Because of integer arithmetic, if you ran two queries, it could have given you the result: 395.4 + 551.8, which truncates the decimal before the arithmetic resulting in 946, whereas if you ran one query with multiple locations, then it would have added first before truncating the decimal resulting in 947. EITHER IS FINE. The test file reflects this discrepancy.
You will submit TWO files in a zip folder. 1) MapQuest class in a python script with the naming convention Lab4_YOURID.py. Ex: Lab4_12345678.py and 2) Your GUI implementation as a python script with the naming convention Lab4_YOURID_ GUI.py. Ex: Lab4_12345678_GUI.py. Do NOT send anything else. You will need to zip your script files by selecting both when you compress (this is necessary because when bulk downloading from Canvas, it will automatically change the file name, and your zip file is a layer that will protect your script file's name from changing).
It is important that you name your file and all of your functions as outlined in this assignment to ensure that your file runs through automation. Failure to name your functions correctly will result in no points awarded for that function. Failure to name your file correctly will result in a 2 point penalty.
Incorrect file submissions (this includes blanks files or "old versions") or files that contain syntax errors will be considered late and awarded no credit (please see syllabus for late policy).
Please double check the file that you have submitted to Canvas to ensure that you have submitted the correct file in the correct format! If you find that you have submitted an incorrect file, you may resubmit your assignment as long as it is before the deadline. Your zip file will have a 2 after it, but this is irrelevant, as your Python file is still protected in the zip folder.
totalDistance(3 points)
totalTime(3 points)
directions (5 points)
pointOfInterest(6 points)
GUI Implementation (3 points)
To ensure that you have named your functions correctly, please be sure to run the test file. The test file will only test for the MapQuest class, NOT the GUI. Please note that passing all the unit tests does NOT ensure full credit for this assignment. The test file checks for basic functionality, and does not cover all possible scenarios.
The functions will be tested for correctness, and if your function works for the test cases in our automation, then you will receive a certain number of points for each successful scenario. Keep in mind that it is up to you to thoroughly test your functions, and it should give the appropriate output for ALL scenarios that are covered in the preconditions.
We will do our best to give partial credit for files that contain syntax errors or contains infinite loops, but this is not guaranteed, and you may receive no credit. It is your responsibility to ensure you are sending a script that does not contain any syntax errors or has logical errors that would cause an infinite loop. It is better to just leave out any functions you were unable to implement rather than send a half written function with syntax errors.
Get Free Quote!
270 Experts Online