为什么当我没有超过每日免费请求数时,我总是收到 MAX_ELEMENTS_EXCEEDED 的错误?

Why I keep getting an error of MAX_ELEMENTS_EXCEEDED when I don't overpass the daily free number of requests?

所以我开发了一个代码,我在其中读取了一个文件,其中包含一些位置(更准确地说是 15 个),其中第一个是车站,其他 14 个位置是公共汽车需要通过以收集病人的地方.为此,我使用 Google Maps API 键来收集真实距离,最后将它们写入 .txt 文件。

import pandas as pd
import googlemaps
from itertools import tee
import numpy as np

#Read CSV file into data frame named 'df'
#change seperator (sep e.g. ',') type if necessary
df = pd.read_csv("D:/Utilizadores/Documents/FEUP/2018-2019/1º Semestre/PDI/Relatório/locais2.txt", sep='\t',
                       engine='python', skiprows=[0], names=["address", "latitude", "longitude"])

lat = np.expand_dims(np.array(df["latitude"]), 1)
lon = np.expand_dims(np.array(df["longitude"]), 1)
coordinates = np.concatenate((lat, lon), axis=1)

coordinates = list(coordinates)
coordinates = [list(coor) for coor in coordinates]


#Perform request to use the Google Maps API web service
#API_key = 'AIzaSyCi8DDz_CCiVwW2JtvT6i-XpJYiEwxFryI'
API_key = 'AIzaSyCpumDcRbbteV64xlGOUQ5_Bah8Ja5gdJ4'
gmaps = googlemaps.Client(key=API_key)

result = gmaps.distance_matrix(coordinates, coordinates, mode='driving')["rows"]
distance_matrix = np.zeros((len(result), len(result)))

for i in range(len(result)):
    for j in range(len(result)):
        distance_matrix[i, j] = result[i]["elements"][j]["distance"]["value"]

np.savetxt("D:/Utilizadores/Documents/FEUP/2018-2019/1º Semestre/PDI/Relatório/locais_output.txt", distance_matrix, delimiter=",", fmt='%d')
print(distance_matrix)

我想要的距离是从一个地方到每个地方,所以我想要的结果是一个15x15的矩阵,其中对角线用0填充。但它一直打印此错误:

"googlemaps.exceptions.ApiError: MAX_ELEMENTS_EXCEEDED".

唯一不出错的方法是限制读取 10 个位置的文件,包括软件仓库:

result = gmaps.distance_matrix(coordinates[0:10], coordinates[0:10], mode='driving')["rows"]

这是为什么?有人吗?

来自 the documentation

MAX_ELEMENTS_EXCEEDED indicates that the product of origins and destinations exceeds the per-query limit.

来自 "usage and billing":

Each query sent to the Distance Matrix API generates elements, where the number of origins times the number of destinations equals the number of elements.

Other Usage Limits
While you are no longer limited to a maximum number of elements per day (EPD), the following usage limits are still in place for the Distance Matrix API:

Maximum of 25 origins or 25 destinations per request.
Maximum 100 elements per server-side request.
Maximum 100 elements per client-side request.
1000 elements per second (EPS), calculated as the sum of client-side and server-side queries.

15 x 15 = 225 大于允许的最大值 (100)

您不想要或不需要某些回复与此无关。