gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:31:40 24 4
gpt4 key购买 nike

所以我开发了一个代码,我在其中读取了一个文件,其中包含一些位置(更准确地说是 15 个),其中第一个是车站,其他 14 个位置是公共(public)汽车需要通过以收集患者的地方。为此,我使用 Google Maps API key 来收集真实距离,最后将它们写入 .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 个位置的文件,包括 depot:

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)

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

关于google-maps - 当我没有超过每日免费请求数时,为什么我总是收到 MAX_ELEMENTS_EXCEEDED 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56405576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com