基于python根据经纬度计算距离、预计驾驶时间

import pandas as pd
import requests
import json
def get_dis_tm(startloc,endloc):
    url = 'https://restapi.amap.com/v3/direction/driving?'
    key = '' 
    link = '{}origin={}&destination={}&key={}'.format(url, startloc ,endloc, key)
    response = requests.get(link)
    dis =""
    tm = ""
    if response.status_code == 200:
        results = response.json()
        if results['status'] == '1':
            dis += str(float(results['route']['paths'][0]['distance'])*1.0/1000)
            tm += str(float(results['route']['paths'][0]['duration'])/60)
        else:
            print(link)
    return dis, tm
startloc = '114.0642970000,22.6750860000'

endloc = '114.0647420000,22.6733940000'
get_dis_tm(startloc,endloc)

 

你可能感兴趣的:(Python学习笔记)