Distance Matrix

介绍

Nextbillion.ai Distance Matrix API 计算并返回一对起点和目的地间的距离和出行时间。无论是从一个出发地到多个目的地,还是从多个出发地到多个目的地,该API都能找到最有效的若干路径以满足您的需求。

举个例子,如果集合为起点{A,B}和目的地{C,D,E},我们可以得到以下附带有距离和时间信息的路线集合。

C D E

A

A -> C A -> D A -> E

B

B -> C B -> D B -> E

The Distance Matrix API返回最高效的路线,附带距离(单位米)和时间(单位秒)信息。

你可以使用SDK的内置方法来请求和呈现结果。另外,在需要时,你可以选择手动处理和可视化数据。

请求

GET

请求参数:

Loading...

POST

POST 去请求 结构:

1https://api.nextbillion.io/distancematrix/json-concise?key={{apikey}}
1curl --location -g --request POST \
2'https://api.nextbillion.io/distancematrix/json-concise?key={{api_key}}' \
3—data-raw '{ "departure_time": {{cur-time}}, "origins": \
4"34.0451,-118.2346|34.1111,-118.2830|33.9502,-118.0776|\
534.0624,-118.1259|33.8606,-118.2828", "destinations": \
6"33.9655,-118.0171|33.9554,-118.0875|33.8642,-118.0225|\
734.1022,-118.0015|33.9366,-118.0993", "mode": "car" }'

Request body

Loading...

Response Schema

Loading...

例子

简单的 API Request

curl --location -g --request --GET "https://api.nextbillion.io/distancematrix/json?origins=12.99135655,77.57688153|1 2.98868026,77.59782421|12.98165485,77.63181317&destinations=12.96258487,77.57001507|12.95907182,77. 59799588|12.96107928,77.62220013&mode=4w&key=<Insert your Key here>"

让我们来看看这个请求中使用的参数-

We are calling for a matrix response for 3 sets of Origins and Destinations. 我们通过给出三组出发点和目的地,可以获得二维矩阵格式的返回。

OriginsDestinations
12.99135655,77.5768815312.96258487,77.57001507
12.98868026,77.5978242112.95907182,77.59799588
12.98165485,77.6318131712.96107928,77.62220013

我们把出行模式设置为 4w ,所以我们将获得的路径信息是4轮特化信息。

简单的 API Response

1{
2  "status": "Ok",
3  "rows": [
4    {
5      "elements": [
6        {
7          "duration": {
8            "value": 922
9          },
10          "distance": {
11            "value": 4415
12          }
13        },
14        {
15          "duration": {
16            "value": 1349
17          },
18          "distance": {
19            "value": 6127
20          }
21        },
22        {
23          "duration": {
24            "value": 1376
25          },
26          "distance": {
27            "value": 7380
28          }
29        }
30      ]
31    },
32    {
33      "elements": [
34        {
35          "duration": {
36            "value": 1232
37          },
38          "distance": {
39            "value": 6199
40          }
41        },
42        {
43          "duration": {
44            "value": 1067
45          },
46          "distance": {
47            "value": 4409
48          }
49        },
50        {
51          "duration": {
52            "value": 1025
53          },
54          "distance": {
55            "value": 5135
56          }
57        }
58      ]
59    },
60    {
61      "elements": [
62        {
63          "duration": {
64            "value": 1522
65          },
66          "distance": {
67            "value": 8366
68          }
69        },
70        {
71          "duration": {
72            "value": 1013
73          },
74          "distance": {
75            "value": 6033
76          }
77        },
78        {
79          "duration": {
80            "value": 642
81          },
82          "distance": {
83            "value": 3648
84          }
85        }
86      ]
87    }
88  ]
89}

API 错误码

Response CodeDescriptionAdditional Notes
200Normal success case.

Normal success case.

400Input validation failed.

Such as missing parameter or parameter with invalid value type (for example value cannot be parsed into number).

401APIKEY not supplied or invalid.

This error occurs when the wrong API key is passed in the request or the key is missing altogether

403APIKEY is valid but does not have access to requested resources.

You might be querying for a geographical region which is not valid for your account, or requesting a service which is not enabled for you.

404Requested host/path not found.

This error occurs when there is a malformed host name used.

422Could not process the request.

There is an underlying map issue which prevents the processing of the request.

429Too many requests.

QPM reached or API request count quota reached.

500Internal Service error.

There was an internal issue with NextBillion.ai services. You can reach out to [email protected] for an explanation.

Directions
Snap To Roads
没找到你要找的内容?