热线电话:13121318867

登录
2019-02-25 阅读量: 772
python如何制作距离时间制作器(1)

# 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]

42.8571
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子