# Python3 program to create Distance
# Time GUI calculator using Tkinter
# import everything from tkinter modules
from
tkinter import
*
# import modules
import
requests, json
# Function for finding distance
# and duration between two places
def
result(source, destination, travel_modes):
# Enter your API key here
api_key =
'Your_api_key'
# base variable to store base url
base =
'https://maps.googleapis.com/maps/api/distancematrix/json?'
# Check travel modes
if
travel_modes ==
"train":
# complete_url variable to store complete url address
complete_url =
base +
'origins ='
+
source +
\
'&destinations ='
+
destination +
\
'&mode = transit&transit_mode = train'
+
\
'&key ='+api_key
# get method of requests module
# return response object
r =
requests.get(complete_url)
else:
# complete_url variable to
# store complete url address
complete_url =
base +
'origins ='
+
source+
\
'&destinations ='+
destination +
\
'&mode ='+travel_modes+'&key ='+
api_key
# get method of requests module
# return response object
r =
requests.get(complete_url)
# json method of response object convert
# json format data into python format data
x =
r.json()
# x contains list of nested dictionaries
# we know dictionary contains key value pair
# Extracting useful information
# from x dictionary
row =
x['rows'][0]
cell =
row['elements'][0]








暂无数据