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

Tia*_*ira 2 google-maps google-maps-api-3 google-distancematrix-api

所以我开发了一个代码,我在其中读取包含一些位置的文件(更准确地说是 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)
Run Code Online (Sandbox Code Playgroud)

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

"googlemaps.exceptions.ApiError: MAX_ELEMENTS_EXCEEDED".
Run Code Online (Sandbox Code Playgroud)

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

result = gmaps.distance_matrix(coordinates[0:10], coordinates[0:10], mode='driving')["rows"]
Run Code Online (Sandbox Code Playgroud)

这是为什么?任何人?

geo*_*zip 6

文档

MAX_ELEMENTS_EXCEEDED 表示起点和终点的乘积超过每个查询的限制

来自“使用和计费”

发送到距离矩阵 API 的每个查询都会生成元素,其中起点数乘以目的地数等于元素数。

其他使用限制
虽然您不再受每天最大元素数 (EPD) 的限制,但距离矩阵 API 仍然存在以下使用限制:

每个请求最多 25 个起点或 25 个目的地。
每个服务器端请求最多 100 个元素。
每个客户端请求最多 100 个元素。
每秒 1000 个元素 (EPS),计算为客户端和服务器端查询的总和。

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

您不想要或不需要某些响应是不相关的。