Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何计算从多个点到目的地的距离?_Python_Google Maps - Fatal编程技术网

Python 如何计算从多个点到目的地的距离?

Python 如何计算从多个点到目的地的距离?,python,google-maps,Python,Google Maps,我有密码: 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

我有密码:

    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
]

我想在一个请求中获得所有的持续时间和距离。这可能吗?

正如geocodezip所指出的,这是距离矩阵的标准特征


在一个请求中?我不确定谷歌是否有这种功能。也许可以尝试迭代源代码,对每个源代码进行请求,并将结果附加到数据结构中。是的,如上所述。您必须使用for循环来迭代原点!这就是距离矩阵的作用,你有什么问题?嘿,很遗憾。我对他们的距离有很多意见和要求。Forloop生成大量请求。