I've set up two sets of address. One across the second row starting at B2 and another down the first column starting at A3. Using a custom function invoking google's api I am trying to get a list of drive times in minutes for all locations in the first column to all locations in the second row. I get an error stating that it has ran to many times in one day. Here is the custom function
function DriveTime(origin, destination) {
var directions = Maps.newDirectionFinder()
.setOrigin(origin)
.setDestination(destination)
.getDirections();
return directions.routes[0].legs[0].duration.value/60;
}
Error: Service invoked too many times in one day: route (line 2)
I understand the error, but how many times in one day can I make this call as a standard free user. And where can I find pricing to increase the amount of daily calls to this service?
Also if anyone knows of a way to accomplish this in less calls than I am attempting, that'd be welcomed knowledge as well.
Technically, your quota as a apps script user without API key/Billing information should be zero. But for whatever reason, Google didn't make changes to charge apps script Maps library when they changed the pricing back in June'18 for everything else related to Maps API. There seems to be a default quota, which is not explicitly mentioned in apps script documentation pages.
If you have had premium plan in the past, you can leverage Maps.setAuthentication(). But if you do not,
This method doesn't work with API keys. Additionally, please note that Premium Plan is no longer available for new customers. If you don't already have a Premium Plan license, please don't call setAuthentication(clientId, signingKey). You are able to use the Maps methods with the default quota allowances.
Which means you cannot extend the default quota allowance.
Your alternative would then be to call the maps api directlyskip oauth using urlfetchapp and parse the response using apps script vanilla javascript(es5).
You can see the pricing here.
Related
I'm using a json script from another stack overflow post and don't know with what frequency I'm calling the external data (from Seatgeek).
I don't want to get cut off from the Seatgeek api so I want to make sure I'm not going to bog down the system - I really only need the data to refresh twice a day.
I would not consider myself a developer so I'm not sure where to look. Can someone please help by taking a look at the script?
According to the Google Sheets API documentation:
Google Sheets API has a limit of 500 requests per 100 seconds per project, and 100 requests per 100 seconds per user. Limits for reads and writes are tracked separately. There is no daily usage limit.
Also, if you want to find the usage and more statistics regarding the API, you can check the Google API console and find all the information there.
For more information regarding your issue, you could check the following documentation:
[1] Google Sheets API;
[2] Google Console API Quota
I need to update this script to pass my key so that I don't go over the limit per day. How would I modify this script to pass my key?
(NOTE: google class information found here: https://developers.google.com/apps-script/reference/maps/geocoder)
function geo2zip(a) {
var response=Maps.newGeocoder()
.reverseGeocode(lat(a),long(a));
return response.results[0].formatted_address.split(',')[2].trim().split(' ')[1];
}
function lat(pointa) {
var response = Maps.newGeocoder()
.geocode(pointa);
return response.results[0].geometry.location.lat
}
function long(pointa) {
var response = Maps.newGeocoder()
.geocode(pointa);
return response.results[0].geometry.location.lng
}
I have never used a google apps script before.
I have this script in place and am using "=geo2zip(cell)" to call the script from my google sheet to get the zip code for incomplete addresses. There are ~28k in my sheet. I have enabled the geocoding api in my google console and my billing info. and created my key but am not sure how to include my key in the script above.
I have also tried using the following to call the api using my key. It is working, but this has resulted in VERY slow responses. At the rate it is taking these to respond, it will take me 10 days to finish updating my 28k records.
CELL M4852--> "https://maps.googleapis.com/maps/api/geocode/xml?address=ADDRESS&key=MYKEY"
NEXT CELL--> "=ImportXML(M4852,"/GeocodeResponse/result/formatted_address")"
The script responds much more quickly, so I would prefer to use that and pass my key. Please let me know if you can help.
UPDATE: I was able to resolve this using Alberto's suggestion below of adding the Maps.setAuthentication.
I believe your issue has more to do with the Google API management than with the scripts themselves. There is a way to limit how much your key is used. According to the Maps Platform documentation:
Manage Your Cost of Use
To manage your cost of use of the Google Maps
Platform APIs, you can set daily limits to all requests to any
billable API.
To view or change daily billable limits for the Geocoding API, do the
following:
Go to the Geocoding API Quotas page in the Google Cloud Platform
Console. From the projects list, select a project. In the Requests
section, on the Requests per day line, click the edit icon, then enter
the preferred total billable daily quota, up to the limit (if any)
specified by Google.
You can basically set how many requests you want to allow per day, which will avoid you going over your limit.
UPDATE
You can link the script to your account using the Maps.setAuthentication(clientId, signingKey) method, according to the docs, it:
Enables the use of an externally established Maps API for Business
account, to leverage additional quota allowances. Your client ID and
signing key can be obtained from the Google Enterprise Support Portal.
Set these values to null to go back to using the default quota
allowances.
Map Documentation Link: https://developers.google.com/apps-script/reference/maps/maps#setAuthentication(String,String)
Quotas URL: https://console.cloud.google.com/project/_/apiui/apiview/geocoding_backend/quotas?_ga=2.141719605.643331044.1560431279-1498828710.1560431279
Documentation URL: https://developers.google.com/maps/documentation/geocoding/usage-and-billing
Google references this:
https://developers.google.com/maps/documentation/javascript/geocoding
And states:
The per-session rate limit prevents the use of client-side services for batch requests, such as batch geocoding. For batch requests, use the Geocoding API web service.
However, when you go to the Geocoding API web services page, I see no reference to batch processing. The above sentence infers that you can do batch processing. I need to send a large number of addresses to get lat and longitude, but doing individual calls for each address is taking extremely long periods of time and need a more efficient method. Hopefully, a single batch call to send all the addresses.
Any ideas of how to batch process addresses on google to get lat and longitude?
I have seen this Google Batch Geocoding API
However, it states you can not which is not what the above google statement infers.
Per the Geocoding API web service documentation:
Other Usage Limits
While you are no longer limited to a maximum number of requests per day (QPD), the following usage limits are still in place for the Geocoding API:
50 requests per second (QPS), calculated as the sum of client-side and server-side queries.
You are just limited to 50 requests per second and have to pay for them (after you use up the $200 credit)
The best way I found to solve this problem is to use the Directions API with up to 27 destinations (origin, destination and 25 waypoints) and get your geolocation for the response legs. The position accuracy is slightly lower than in the geocode case from what I observed, but it is still a great tradeoff.
In the worst case you will have to call the Directions API twice when one or more addresses are not found in your call. The good thing in this case is that the Directions API will give you a response with the geocoded_waypoints which will specify the NOT_FOUND locations with a geocoder_status. After that, you can eliminate the bad ones and call again.
There are currently no available feature for a Geocoding API to handle multiple address at a single call, however, you may implement the batch process via cURL, by doing this, you can call multiple requests at once automatically. Implementation will be up to your use case as well.
Quick question, just to clarify the wording and meaning (because it's changed a couple of times for Map loading...)
There are the two following statements in the Places API FAQs:
The Google Places API has the following query limits:
Users with an API key are allowed 1 000 requests per 24 hour period.
Users who have verified their identity through the APIs console are
allowed 100 000 requests per 24 hour period. A credit card is required
for verification, by enabling billing in the console. We ask for your
credit card purely to validate your identity. Your card will not be
charged for use of the Places API. While the lower limit is sufficient
for development and testing, we recommend enabling the higher limit
before launching your application. It is possible to request an
additional quota. If granted, the additional quota is free of charge.
If, at some stage in the future, an option becomes available to pay
for an additional quota, that quota will be over and above the
existing free quota, and you will need to sign up for it explicitly.
Note that some services may have a multiplier:
The Text Search service is subject to a 10-times multiplier. That is,
each Text Search request that you make will count as 10 requests
against your quota. The Radar Search Service is subject to a 5-times
multiplier. That is, each Radar Search request that you make will
count as 5 requests against your quota. If you've purchased the Google
Places API as part of your Maps API for Business contract, the
multiplier may be different. Please refer to the Google Maps API for
Business documentation for details.
This implies that use of the Google Places API is restricted to 100,000 queries per day, or 10,000 if you're doing a Text Search.
However, on the Uplift page, it says the following:
If you are developing a web based application that only needs to
search for places, and is not submitting new places or Place Bumps,
you should use the Places library of the Maps API rather than using
the Places API web service. The Places library assigns a quota to each
end user rather than to each key. This means that your available quota
increases with your user base rather than being capped at a fixed
amount.
I am using the Places API in the following way:
https://maps.googleapis.com/maps/api/js?key=XXX&libraries=places
...
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
And also for some details searching and photo searching.
Therefore my question is; Given my usage of the Places API, am I subject to the 100,000 queries limit on my app, or am I essentially uncapped at an app level, as my quota is per end-user? (i.e. per unique IP? if I had 10,000 users I have an effective quota for my entire user base of 100,000*10,000?)
EDIT:
For clarity: if I throw my API key into https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=XXXX, it will increment my Places quota count on the Google API console, however if I run queries through my JS app, I see no quota use change. I want to make sure that i'm not suddenly going to be hit with a massive quota result.
Use of the JavaScript API services, like those provided by the Places library, have quota assigned to each end-user. It's a very similar setup as objects like the google.maps.Geocoder, which has been discussed in a bit more detail in this Geocoding Strategies article.
You may apply for an uplift to the quota so that the restriction is taken away and you have unlimited access:
https://docs.google.com/forms/d/18pkOdu0uofeI8tbQoReDVfkbOIAscLvjiKc9ZP06hEM/viewform
This form is applicable to Android, IOS and Web.
I have a Google spreadsheet with one column of physical addresses, and I want to have a second column be the time in minutes to walk between the address in column 1 and a second address (as determined by Google Maps). Any recommendations on how to accomplish this task?
From my understanding of the Google Maps terms of service, they:
don't like people using their service as a "batch geocoder". This means that
you will need to throttle your requests (place delays between each successive request, to avoid the OVER_QUERY_LIMIT error)
it is against the terms of service to use the geocoder (and maybe the distance service) without displaying a map graphic
If you still want to proceed,
you need some way of extracting the address from your spreadsheet. I think there's a Google docs API that will help you do that. I also found some custom Javascript code that does that for you easily. I don't have a link anymore :(
once you have the addresses readable from the Google Maps Javascript API, you can call the distance or directions API to get the walking distance
then you need to save that back to the spreadsheet.
It sounds like a possible application for the Distance Matrix Service.
But you can only use it if you will be displaying a map
Use of the Distance Matrix API must relate to the display of
information on a Google Map; for example, to determine
origin-destination pairs that fall within a specific driving time from
one another, before requesting and displaying those destinations on a
map. Use of the service in an application that doesn't display a
Google map is prohibited.