def get_dis_tm(origin, destination): url = 'https://restapi.amap.com/v3/direction/driving?' key = '208ce530fdd2dc162c8831657fff3232' #这里就是需要去高德开放平台去申请key,请在xxxx位置填写 link = '{}origin={}&destination={}&key={}&strategy={}'.format(url, origin ,destination , key,"2") response = requests.get(link) dis, tm = 999999, 999999 if response.status_code == 200: results = response.json() if results['status'] == '1': for temp in results['route']['paths']: print(temp['distance']) if results['status'] == '1': dis = int(results['route']['paths'][0]['distance']) tm = int(results['route']['paths'][0]['duration']) else: print(link) response.close() return dis, tm
标签:origin,计算,网格,距离,results,tm,key,response,dis From: https://www.cnblogs.com/cocotun/p/17583417.html