I am working on a project to display routes using google map distance API between point A and B coming from a dataframe, I keep getting the error of " [directions layer] You have sent too many directions request. Wait until your quota replenishes". This happens only when the number of requests exceed 10. ALTHOUGH, I have added a 1 second delay after the 10th request with no luck! I also tried to send the requests in batches with a size of 10 each, that didn't work too! Moreover, I've read the API documentation
I have billing setup although I am on the free trial apparently I still have over $300 of credit.
Here is a simulation of my code, a very simple one, for your kind advice
import gmaps
import time
dict_k ={}
dict_k['st_coordinates'] =[ '24.760669, 54.704782','25.168596, 56.355549','25.004274, 55.063742','25.000252, 55.060932',
'24.872900, 55.137325','24.537609, 54.383664','24.050339, 53.470903','24.211435, 55.424501',
'24.196804, 55.855923','24.308309, 54.675861','24.988239, 55.104435','24.985047, 55.071542',
'24.306433, 54.490205','25.000252, 55.060932','24.536064, 54.383048' ]
dict_k['en_coordinates'] =[ '24.454036, 54.376656','24.130453, 55.801786','23.931339, 53.045892','24.171,54.408',
'24.454036, 54.376656','24.130453, 55.801786','23.931339, 53.045892','24.171,54.408',
'24.454036, 54.376656','24.130453, 55.801786','23.931339, 53.045892','24.171,54.408',
'24.454036, 54.376656','24.130453, 55.801786','23.931339, 53.045892']
key = 'AIzA...............'
dataframe = pd.DataFrame.from_dict(dict_k)
def draw_map (dataframe,key):
gmaps.configure(key)
fig = gmaps.figure()
for i in range(len(dataframe)):
start_point = eval(dataframe['st_coordinates'].iloc[i] )
end_point = eval(dataframe['en_coordinates'].iloc[i] )
layer = gmaps.directions_layer(start_point, end_point)
fig.add_layer(layer)
if i >10:
time.sleep(1)
return fig
df = draw_map(dataframe,key)
df
Here's a link to the API guide. Spells it out quite clearly. https://developers.google.com/maps/premium/previous-licenses/articles/usage-limits
You can exceed the Google Maps Platform web services usage limits by:
This means that the web service will stop providing normal responses and switch to returning only status code OVER_QUERY_LIMIT until more usage is allowed again. This can happen:
Upon receiving a response with status code OVER_QUERY_LIMIT, your application should determine which usage limit has been exceeded. This can be done by pausing for 2 seconds and resending the same request. If status code is still OVER_QUERY_LIMIT, your application is sending too many requests per day. Otherwise, your application is sending too many requests per second.