Google distance matrix api quota behaves unreliable - google-maps

I'm talking specifically about the quota of type elements per minute per user. I set this value to 150. The documentation says number of elements is origins x destinations.
This is how I call the api:
const distanceMatrixService = new google.maps.DistanceMatrixService();
const request = {
origins: [locator.searchLocation.location],
destinations: locator.locations.map(function (x) {
return x.coords;
}),
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: units,
};
distanceMatrixService.getDistanceMatrix(request, distancesReceivedCallback);
I get a proper response having 1 origin and locator.locations contains 3 destinations. As far as I add a 4th destination I receive an error response:
{
"destination_addresses" : [],
"error_message" : "Distance Matrix Service: You have exceeded your rate-limit for this API.",
"origin_addresses" : [],
"rows" : [],
"status" : "OVER_QUERY_LIMIT"
}
The other quotas are all set to a very high value so they should not be a problem.
Why am I exceeding the quota of 150 with 4 destinations but not with 3?
From the documentation my requests should count as 4 (1 x 4) elements. The only way the api works reliable is when I set this specific quota to unlimited which is not desireable for my use case.

Elements Per Minute / 60 = Elements per second
Elements per minute seems to have been misunderstood. From what I can see, the OVER_QUERY_LIMIT error appears because the quotas you have set is working as intended.
Let me explain how Elements Per Minute Work:
When setting up your quota using Elements Per Minute, you should divide it with 60 to get Elements Per Second. The result would be your maximum query "every" second. So when you have set your Elements Per Minute to 150, this means that your maximum Elements Per Second is at 2.5 Elements.
150 Elements per minute / 60 = 2.5 Elements per second
The API might be rounding up the 2.5 to 3 and that explains why you are not receiving an OVER_QUERY_LIMIT error if you implement 3 elements (1 origin x 3 destinations) and receive it when you implement 4 elements (1 origin x 4 destinations) because, ofcourse, you are "OVER" the quota of elements per second that you have set.
I hope this answers your question. And please feel free to confirm it in the comments if this fixed your issue.

Related

Distance matrix api for Google

I am using Google Distance Matrix API. But I am unable to figure out the API cost, it has written on their website that "price per element". So, if I have two origins and 1000 destinations, then what will be my total API cost, and is the example program with Google OR tools is enough to run 1000 destination distance API call and solve the matrix?
Please Help!!
Each Distance Matrix API call generates a number of elements (the number of origins times the number of destinations, e.g. 10 origins * 10 destinations = 100 elements) and each element costs $0.005 as per Google's documentation. So in the provided example, you'd be billed 0.005 * 100 = $0.5 per call to the Distance Matrix API.
Also, note that you cannot add two origins and 1000 destinations to a single request. You are limited to a maximum of 25 origins or 25 destinations per request, hence in order to query 1,000 destinations you'd need to make multiple Distance Matrix API requests.
Hope this helps!

how to increase the number of resulting places for google-nearby-places-web-service, as i always get up to 20 places only

i only get 20 place nearby no matter i expand the range area 500, 2000, 3000 in meters just appear new places but it doesn't add to the old one replace some so always have at max of 20 place every time
i tried running the api on other devices and expanded the search area smae problem remains
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=30.050203,31.221214&radius=1500&key=SOMEKEY
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=30.050203,31.221214&radius=3000&key=SOMEKEY
expected results to have as much as places near me so i expect when i expand the search area to 3000 meters instead of 1500 to find more plcaes
BUT i always have 20 places no matter what !!
Places API Nearby Search returns up to 20 establishment results per query, regardless of the radius value you pass to it.
Using pagetoken you can get up to 60 places, split across 3 pages (3 queries).
Check out Google's documentation to learn more: https://developers.google.com/places/web-service/search#PlaceSearchPaging
Hope this helps.

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

So I developed a code where I read a file with some locations (15 to be more precise), where the first one is the depot and the other 14 locations are the places where a bus needs to pass to collect patients. In order to do that, I use Google Maps API key in order to collect the real distances and write them in a .txt file in the end.
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)
The distances I want are from one place to every place, so the result I want is a matrix of 15x15 where the diagonal is filled with 0's. But it keeps printing this error:
"googlemaps.exceptions.ApiError: MAX_ELEMENTS_EXCEEDED".
The only way to not have an error is to put a limit on the reading of the file of 10 locations, including the depot:
result = gmaps.distance_matrix(coordinates[0:10], coordinates[0:10], mode='driving')["rows"]
Why is that? Anyone?
from the documentation
MAX_ELEMENTS_EXCEEDED indicates that the product of origins and destinations exceeds the per-query limit.
from "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 which is greater than the maximum allowed (100)
That you don't want or need some of the responses is not relevant.

Google Photos API, pageSize Parameter not returning expected results

Using the Google Photos API Explorer I am trying to limit the number of albums returned using the albums.list method.
If I set pageSize = 10, the api explorer returns 5 albums, if I set it to 3 in returns 1 album.
Any suggestions as to why I am not seeing the same number of albums in the response as is set via the pageSize parameter?
Thanks
The page size describes the desired maximum number of results, but it is no guarantee.
If you need at least 10 results from a single request, your best option would be to request a higher page size as you have found. Alternatively, you can always make additional requests using the nextPageToken.
(We have some plans to improve this in the future and return a number of results that's equal, or even closer, to the page size. Unfortunately, at the moment we can't guarantee the number of results in a request, but we always try to fill a page size if possible.)

If you make a single googlemaps API request with multiple origin/dest addresses, does that count as a single request?

Since there is a free quota of 2500, I am wondering if there's anything I could do to optimize the number of requests I make to the API.
If I make a single request with 1 origin address & 2 destination addresses, does that count as 2 requests in terms of the quota?
Thank you
The answer to your question is NO, In Distance Matrix API you have a usage limit of 2500 free elements per day (Standard Plan)[2].
where the:
Nº of Elements = Nº Origins x Nº Destinations [1]
and you can have:
A maximum of 25 origins or 25 destinations per request.
A Maximum 100 elements per request.
A Maximum 100 elements per second*, calculated as the sum of client-side and server-side queries.[2]
[1] https://developers.google.com/maps/faq#usage_quotacalc
[2] https://developers.google.com/maps/documentation/javascript/distancematrix#UsageLimits