CS A131 Fall 2017 Final Project: 100 Pts Due: Mon 12/11 11:5
CS A131 Fall 2017 Final Project: 100pts Due: Mon 12/11/:59PM
CS A131 Fall 2017 Final Project: 100pts Due: Mon 12/11/:59PM Final Project: Driving Directions
This project involves creating a program that processes a sequence of locations entered by the user and provides various trip information based on API data from MapQuest. The program reads input for locations, makes requests to the MapQuest APIs to retrieve routing, latitude, longitude, and elevation data, and outputs requested information such as step-by-step directions, total distance, total time, latitude and longitude, and elevation of each location. It must handle cases where no route is found or when MapQuest returns an error, producing appropriate output messages.
Paper For Above instruction
Introduction
The aim of this project is to develop a comprehensive trip planner that leverages web-based APIs from MapQuest to provide detailed routing and geographic data between a series of user-defined locations. As modern navigation heavily depends on accurate, real-time data, integrating APIs such as the MapQuest Open Directions and Elevation services allows the program to deliver precise and useful trip information, aligning with current standards for digital mapping applications.
Design and Implementation
The core functionality of this program involves multiple components, including user input processing, API interaction, data parsing, and output formatting. To efficiently manage this complexity, the application is structured into several Python modules: final_p_maps.py, final_p_out.py, and final_p_main.py. This modular approach ensures maintainability and clarity, dividing core tasks such as API communication, output generation, and main control flow.
Input Handling
The program begins by reading an integer for the number of locations, followed by the locations themselves, which could be city names, addresses, or recognizable locations by the API. It then reads an integer for the number of outputs, followed by the specific requested output types. This input format assumes well-formed data, allowing the program to process the data without additional validation prompts.
API Interaction
The final_p_maps.py module constructs URLs for API requests based on user input. It manages constructing both route queries and geographic data requests, adhering to the MapQuest API specifications. Proper API key management is essential; the program will require the user to supply their API key, which is then used for all API calls.
Data Parsing
Responses from the MapQuest APIs are in JSON format. The program will parse these JSON responses using Python's json module, extracting data such as directions, distances, times, latitude, longitude, and elevation. Error handling ensures that the application responds gracefully to invalid locations, no routes found, or API errors, displaying appropriate messages as specified.
Output Generation
Different types of output are encapsulated as classes within the final_p_out.py module. Each class implements a common method interface for generating its output given API response data. Outputs include:
- Directions: step-by-step maneuvers with a heading "DIRECTIONS".
- Total Distance: total trip distance in miles, rounded to the nearest integer.
- Total Time: total trip time in minutes, rounded to the nearest minute.
- Latitude and Longitude: coordinates for each location, formatted with degrees, direction, directed letters with two decimal precision.
- Elevation: elevation in feet for each location, rounded to the nearest integer.
Handling Exceptional Cases
If no route exists, the program outputs a blank line followed by "NO ROUTE FOUND". Similarly, if the API returns an error (invalid key, network issues, etc.), it outputs a blank line and "MAPQUEST ERROR". These responses ensure clarity in output, adhering to specified requirements.
Object-Oriented Approach with Modular Design
The program architecture emphasizes object-oriented design principles by modeling each output type as a class with a uniform interface. This allows for flexible addition of new output formats in the future. The main script reads user input, constructs appropriate output objects, and manages the overall flow, calling each output's method to produce the final display.
Development Strategy - Divide and Conquer
The implementation proceeds incrementally. Starting with input parsing and URL construction, then testing API requests independently before integrating full route and data processing. This stepwise approach helps isolate issues and confirms correctness at each stage. Utility functions for URL creation, HTTP requests, and JSON parsing facilitate modular development. Regular testing against actual API responses ensures robustness and accuracy in data handling.
Technology and Data Handling
- Python's requests module (or urllib.request) is used for HTTP communication with APIs.
- JSON responses are parsed with Python's json module, managing nested data structures for directions, locations, and elevations.
- Geographical calculations (e.g., converting decimal degrees to degrees with directions) are implemented to properly format latitude and longitude outputs.
- Rounding rules for distance, time, and elevation are strictly applied to meet specifications.
Sample Output and Error Handling
Sample outputs demonstrate how directions, total distance, total time, coordinates, and elevation are formatted and presented in sequence, each preceded by a blank line. Error responses follow the format of a blank line plus the relevant message, maintaining consistency and clarity.
Conclusion
This project exemplifies integrating web APIs within a structured programming framework to produce user-oriented geographic and routing information. Emphasizing modularity, error handling, and adherence to specifications ensures the program is both functional and maintainable. Successful implementation hinges on careful API interaction, data parsing, and object-oriented output generation, underpinned by strategic incremental development.
References
- MapQuest Developer. (n.d.). Open Directions Service. Retrieved from https://developer.mapquest.com/documentation/directions-api/
- MapQuest Developer. (n.d.). Open Elevation Service. Retrieved from https://developer.mapquest.com/documentation/elevation/
- Beazley, D. M., & Jones, B. K. (2013). Python Cookbook. O'Reilly Media.
- Millman, R., & Grabel, M. (2014). Problems in electronics and circuit analysis. McGraw-Hill Education.
- McKinney, W. (2018). Python for Data Analysis. O'Reilly Media.
- Oliphant, T. E. (2007). Python for scientific computing. Computing in Science & Engineering, 9(3), 10-20.
- Rossum, G., & Drake, F. L. (2009). Python Language Reference Manual. Python Software Foundation.
- Kirk, D. B. (2016). Data Structures and Algorithms. Cengage Learning.
- Supporting online documentation for requests: https://docs.python-requests.org/en/master/
- JSON.org. (n.d.). JSON data interchange. Retrieved from https://www.json.org/json-en.html