0

Google allows a domain to load the google map API 25,000 times per day for free. Once that limit is hit then your map stops working for the rest of that day unless you buy more API loads.

How can my javascript detect when that limit is reached so I can fail as gracefully as possible by displaying an informative message?

Gmap4 guy
  • 321
  • 1
  • 2
  • 11

2 Answers2

0

Take a look at the API Reference for Javascript.

Let's say you're making a GeoCoder Request, of the form Geocoder().geocode(request:GeocoderRequest, callback:function(Array<GeocoderResult>, GeocoderStatus))

That second parameter in the callback is going to give some useful information about the response, including if it is over the rate limit.

To check if you are over the limit, compare the status code to the constant

google.maps.GeocoderStatus.OVER_QUERY_LIMIT

and handle the error accordingly.

Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
  • 1
    Thanks Andrew but I think I am asking a different question. Google's documentation for their maps API does not have any info showing how to detect when the 25,000/day API load limit is reached. If there is a way to trigger a callback routine, I have not found it yet. – Gmap4 guy Feb 14 '17 at 14:46
  • Which API are referring to? This one? https://developers.google.com/maps/documentation/javascript/ – Andrew Brooke Feb 14 '17 at 14:52
  • Yes, I am referring to the google map javascript API which I am loading from https://maps.googleapis.com/maps/api/js. I seem to recall seeing a solution a couple of years ago but cannot find it. – Gmap4 guy Feb 14 '17 at 14:54
  • 1
    I've seen a couple of similar questions floating around on StackOverflow (including this one from 5 years ago.. http://stackoverflow.com/questions/8665696/how-to-detect-that-the-25000-request-per-day-limit-has-been-reached-in-google-ma) and it seems like it's still only possible to check the API Usage through the process described here: https://support.google.com/googleapi/answer/7036164, and not programmatically... – Andrew Brooke Feb 14 '17 at 15:00
  • I think Andrew is correct with the above. Monitoring via the API Console seems to be the way to go, afaik. – MrUpsidown Feb 14 '17 at 15:04
  • 1
    Yeah, so far I am hitting that same deadend. If this is currently not doable in javascript then I will post an enhancement request in google's bug tracker. – Gmap4 guy Feb 14 '17 at 15:08
  • Monitoring the API console will tell **me** why my map stopped working but it sure leaves my users with an awful experience. Worse yet, most will blame me for building a crummy map that does not work. Might be time to look at Leaflet. – Gmap4 guy Feb 14 '17 at 15:11
  • It would be nice to hear something definitive from Google in this point. (hint hint) – Gmap4 guy Feb 14 '17 at 15:29
  • 2
    Here is my feature request to Google. [https://code.google.com/p/gmaps-api-issues/issues/detail?id=11460](https://code.google.com/p/gmaps-api-issues/issues/detail?id=11460) If this feature would help you, please give it a star. – Gmap4 guy Feb 14 '17 at 16:05
  • @Gmap4guy Subscribed! – MrUpsidown Feb 14 '17 at 17:00
  • For anyone who comes upon this thread, the enhancement request I posted on Google's issue tracker has been merged into: https://code.google.com/p/gmaps-api-issues/issues/detail?id=11293 – Gmap4 guy Feb 15 '17 at 12:31
0

Good news from Google. Looks like they posted a solution last month. https://developers.google.com/maps/documentation/javascript/error-messages

I search SO on OverQuotaMapError but got no hits

Here is the post I made today on SO seeking advice for how to catch this 'error' with code.
How to catch OverQuotaMapError for a Google map?

Gmap4 guy
  • 321
  • 1
  • 2
  • 11