我有代码:
orig_lat = 48.864716 # Paris lat
orig_lon = 2.349014 # Paris lon
dest_lat = 52.518623
dest_lon = 13.376198
google_url = 'http://maps.googleapis.com/maps/api/'
fn_url = 'distancematrix/'
opt_url = '&language=en-EN&sensor=false'
url = "%s%sjson?origins=%s,%s&destinations=%s,%s&mode=driving%s" % (
google_url, fn_url, str(orig_lat), str(orig_lon),
str(dest_lat), str(dest_lon), opt_url
)
ret = requests.get(url)
和谷歌回复:
{
"destination_addresses" : [ "Paul-Löbe-Allee, 10557 Berlin, Germany" ],
"origin_addresses" : [ "18bis Rue Tiquetonne, 75002 Paris, France" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1,045 km",
"value" : 1045157
},
"duration" : {
"text" : "9 hours 58 mins",
"value" : 35905
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
但我有一个目的地点和许多原点:
dest_lat = 52.518623
dest_lon = 13.376198
origins = [
(48.864716, 2.349014), # Paris
(40.415363, -3.707398), # Madrid
(52.237049, 21.017532) # Warsaw
]
我希望在一个请求中获得所有持续时间和距离。这可能吗?
答案 0 :(得分:1)