Cap Google Maps API spend and set alerts that work
A surprise Maps bill usually comes from crawlers, a duplicate loader or a leaked key, running unnoticed for weeks. A budget tells you after the money is spent. A quota is what actually stops the requests. You want both, set up in the right order.
How to tell this is your problem
- Map requests far above your visitor numbers.
- Usage concentrated on a few pages, a single API, or one key.
- Budget alert emails arriving after the spend has happened, or going to someone who has left.
- Calls to APIs your site doesn't use, which points to a leaked key.
Budgets warn, quotas stop
Google is explicit on both points. Its billing documentation says that setting an alerts-only budget “doesn't automatically cap Google Cloud or Google Maps Platform usage or spending.” Its Maps cost guidance says that “to put a hard cap on usage of an API, lower its per-day quota.”
| Tool | What it does | What it doesn't do |
|---|---|---|
| Budget | Emails you when actual or forecast spend crosses a threshold | Stop any requests |
| Per-day quota | Refuses requests to that API for the rest of the day once the cap is reached | Know anything about money; it counts requests |
| Key restrictions | Stop other sites and servers using your key | Limit volume from your own site |
| Lazy loading | Stops map loads from visitors and bots who never look at the map | Cap anything on its own |
A quota is a blunt tool. When it is reached, your own map shows OverQuotaMapError until the reset at midnight Pacific time. Set it high enough that real traffic never reaches it, and low enough that a runaway bot can't cost you more than you can absorb in a day.
Step 1: restrict every key
Google's first recommendation for blocking unwanted traffic is to restrict your API keys to your apps and to the APIs they use. Do this before setting caps, or a leaked key will use up the cap your own site depends on.
- 01Open APIs & Services → Credentials and click each key.
- 02Browser keys: under Application restrictions, choose Websites and list your domains. See referrer patterns.
- 03Server keys: restrict by IP address instead.
- 04Under API restrictions, allow only the APIs each key needs.
Step 2: set per-day quotas
- 01Work out your real peak. Open Google Maps Platform → Metrics, look at the last few months for each API, and note the busiest day.
- 02Open Google Maps Platform → Quotas (or IAM & Admin → Quotas & System Limits) and select the Maps JavaScript API.
- 03Find the per-day quota for map loads, click Edit, enter a value comfortably above your busiest day, and submit.
- 04Repeat for every other API the project uses, such as Geocoding, Places and Maps Static API. Web-service APIs are often the ones abused by a leaked key.
- 05Write the values down somewhere your team can find them. Whoever sees OverQuotaMapError next needs to know a cap exists.
Start at about double your busiest normal day. A seasonal spike or campaign then fits under the cap, and a bot running all day can't exceed about twice your usual daily usage. Review the value whenever traffic grows.
Step 3: budget alerts that reach someone
- 01Open Billing → Budgets & alerts for the billing account and create a budget scoped to the project that serves your maps.
- 02Set the amount to what you expect to pay in a normal month. Google's default alert thresholds are 50%, 90% and 100% of the budget, against actual spend. Add a forecast-based threshold if you want earlier warning.
- 03Check who receives the emails. By default they go to Billing Account Administrators and Billing Account Users. If those are a former developer or an unread inbox, add a monitored address or a notification channel.
Google notes there is a delay between usage and the costs appearing in Cloud Billing, so a budget alert always lags the traffic that caused it. That is why the quota comes first.
Automatic billing shutdown: use with care
Google documents using budget notifications through Pub/Sub to disable billing on a project automatically. That does stop spend, but disabling billing stops all Google Maps Platform services on the project. Every map on your site goes grey with BillingNotEnabledMapError until someone re-links billing. See re-enabling a suspended project. For most sites, per-day quotas are the safer hard limit because they recover on their own each day.
Step 4: cut the requests you don't need
- Load maps on interaction. A placeholder that becomes a map on click or scroll means crawlers and visitors who never look at it don't create map loads. See lazy-loading a map.
- Remove sitewide maps. A map in the footer of every page costs a map load on every page view.
- Fix duplicate loaders. Two plugins loading the API can each create a map. See finding a duplicate loader.
- Use one map per page. Google's cost guidance recommends reusing a single map and updating its viewport and markers.
- Consider a static image. Google suggests the Maps Static API for thumbnails and maps with no interaction.
Confirm it is working
Watch the metrics graph for a week. Requests should follow your visits, and no API should come near its cap in normal traffic. Check that the first budget email actually arrived in a monitored inbox.
Scan the pages that carry maps. A scan lists every Maps request each page makes, which shows duplicate loaders and unexpected API calls. Add those pages to monitoring as well, so you get an email if a quota you set too low starts breaking the map.
To see what your current traffic would cost, try the free Google Maps API cost calculator.
Common questions
Can I set a hard spending limit on Google Maps?
Not with a standard alerts-only budget, which only sends emails. The practical hard limit is a per-day quota on each API, which caps the number of requests and so caps the cost.
Does a Google Cloud budget stop my API usage?
An alerts-only budget does not. It sends notifications when spend crosses its thresholds. Usage and charges continue.
What happens to my map when a quota is reached?
Requests to that API fail for the rest of the day and visitors see OverQuotaMapError. Daily quotas reset at midnight Pacific time.
Who gets Google Cloud budget alert emails?
By default, the Billing Account Administrators and Billing Account Users on the billing account. You can add other recipients through notification channels.
A scan tells you in about twelve seconds, from a clean session.