Here specs any help on python how this program?
The general form of a distance query is:
https://maps.googleapis.com/maps/api/distancematrix/json?parameters
where parameters denotes a series of parameters. The parameters we will use are:
· origins: the origin city and state[1]
· destinations: the destination city and state
· sensor: false, which tells the server that your application does not use a GPS locator
· mode: one of 'driving', 'biking, or 'walking'
There are no spaces in the query. Parameter assignments are separated using the ampersand (&) symbol and words in the city are separated using the plus (+) sign.
Some examples are listed next. Copy and paste each one into a browser to see what is returned. Then in own examples to see how changing parameter values changes the response you get back. What happens, for instance, if you make up some city names and/or state abbreviations? What happens if there is not roadway between the origin and destination?
Parsing the Result
As distance calculation is part of the map API, and not its own API, the entire result is returned as a single string, which must be parsed. The string returned by the first query above, which finds the driving distance between New York, NY and Lansing, MI, is as follows:
You will need to parse this string to extract the information required. You need to extract the value , which is the number of meters from Lansing to New York.
In testing queries, you should have discovered that the server "guesses" a location if it cannot exactly match the values indicated for the cities. Your program does not need to check that the response is for the correct location—just assume that the distance returned in a response is correct. But your program does need to handle the situation where the response does not contain a distance. (See below.)
Project Description / Specification
Need class called Tour. An instance of this class is to be instantiated with two US cities, and is used to fetch information from the web. Specifically, the class must define:
- __init__ The constructor takes two strings as arguments, each giving a city name and state abbreviation, indicating the origin and destination. For example: Tour("New York, NY", "Los Angeles, CA")represents a tour that starts in New York city and ends in Los Angeles.
- distance This method takes a single (optional) argument indicating a mode - one of the strings 'driving' (default), 'biking, or 'walking'. It returns the total distance (in meters) covered by the tour for the indicated mode. This method is where you will use urllib functions to get data from the web to find the distances between two locations in the tour and calculate the total distance. If a response does not contain a distance value, the method should raise a ValueError exception.
Graphical User Interface Description:
Need class called TourGui. An instance of this class is to be instantiated in the main. Specifically the class must define:
1. __init__ The constructor doesn't take any arguments. The constructor creates two frames in the window, a top frame and buttom frame. The top frame contains a label and an entry widget for the following fields: origin, destination, and mode. The bottom frame contains a label and text widget for Distance and a button widget for Get Distnace. The GUI should like the following:
2. onClick This method is the event handler for the Get Distance Button. When the button is clicked, the origin, destination and mode fields are read, the query is made and the distance between the origin and the destination is displayed. If the user enters an invalid mode, a message box shows up indicating invalid mode was entered:
If the distance was not found between the origin and the destination, a message box shows up indicating the distance was not found:
[1] The parameter names are plural because you can request a distance matrix, indicating distances between a set of potential origins and a set of potential destinations. However, we will just use a single city for each.
Final ProjectParsing the Result*BackgroundAs distance calculation is part of the map API , and not its own API , the entire result is returned as aThe acronym API is short for* Application Programming Interface . " It is usually a collection ofsingle string , which must be parsed . The string returned by the first query above , which finds thefunctions , methods or classes that supports the interaction of an application program ( the program Youdriving distance between New York, NY and Lansing . INIT, is as follows :`write as a developer ; with other programs that run on a remote server . Google has several API'S*available for developers ( https : / / developers . google . com ) to query information from services google*provides such as google map . We will be using the map API for purposes of finding distances between" DESTINATION SQUEEGEES`` [ " LANSING , MI , USA " ] .cities in the U . S Lavon as Google Map Distance Matrix API" DELIQUID. Add^FERRER`` [ "NEW YORK, NY , USA " ] .(https : // developers . google . com maps / documentation distance _ matrix ] . It is based on creating a queryusing the http protocol of the web . Essentially , you send a web address ( with the query embedded in" ELETIENES* " : [the web address ) and a web page is returned with the requested information , albeit in a rather odd form( It is not HINI format ) ." DIEFENCE."" 1, 092 KITI "`$ 1091921The general form of a distance query is :`if" durationhttps : / / maps . google apis . com /' maps / api /' distance matrix ,' jeon ? ParameterE*"10 hours 12 quizz "`KATHIE" : 3571 1Where parameters denotes a series of parameters . The parameters we will use are`" Status. " : " OK?"origins . the origin city and state !*destinations : the destination city and statesensor : false , which tells the server that your application does not use a GPS locator*trade : one of" driving ,"biking , or" walking*" statue* " : " OR "There are no spaces in the query . Parameter assignments are separated using the ampersand (^)symbol and words in the city are separated using the plus ( + ) sign .`You will need to parse this string to extract the information required . In this response , You will need toSome examples are listed next . Copy and paste each one into a browser to see what is returned . Then*extract the value 1091921 , Which is the number of meters from Lansing to New York .create your own examples to see how changing parameter values changes the response you get back.What happens , for instance , if you make up some city mathes and or state abbreviations ? What happensIn testing queries . You should have discovered that the server " guesses" a location if it cannot exactlyif there is not roadway between the origin and destination ?"match the values indicated for the cities . Four program does not need to check that the response is forthe correct location - just assume that the distance returned in a response is correct . But Your programhttps: / / maps . Food leapis . com / maps / api / distance matrix / is on ? origins = New + York' + NY & destinatidoes need to handle the situation where the response does not contain a distance . ( See below . )Ons = Lansing + M| { mode = driving `` sensor = false aker = AlEasy AFH IF SE 3_ SKQ C Kh H Wudwho E Com NRdavEQProject Description / Specification*https: "/ maps . googleapis . com / maps/ ani/ distancematrix ison ? origins = Lansing + MIT &c destinations = SacranCreate a class called Tour . An instance of this class is to be instantiated with two ITS cities , and isEnto + [ Act_made = bicycling < sensor = False & Key = AlzaSy AF H I F S E 3_ OKD C Kh H Wudwho E Com N RdavEQused to fetch information from the web . Specifically , the class must define :`1 .init, The constructor takes two strings as arguments , each giving a city name and stateabbreviation , indicating the origin and destination . For example : Tour !" NEW York , NY"!" LOS ANGELES ,\CA " / represents a tour that starts in New York city and ends in LosAngeles .2.distance. This method takes a single ( optional ) argument indicating a made - one of thestrings " driving ' ( default ) . " biking , or "walking ' . It returns the total distance ( inmeters ) covered by the tour for the indicated made . This method is where you will use willitfunctions to get data from the web to find the distances between the locations in the tour andcalculate the total distance . If a response does not contain a distance value , the method shouldraise a ValueFRERE exception .The parameter names are plural because you can request a distance matrix , indicating distances*between a set of potential origins and a set of potential destinations . However , we will just use a single