Optimizing Web Service Usage

Important: The Google Maps Platform Premium Plan is no longer available for sign up or new customers.

Overview

If your application exceeds the usage limits for a Google Maps Platform web service, the service returns an error message. If your application continues to exceed the usage limits, it might be blocked from accessing the web service and, in some cases, receive "403 Forbidden" responses.

If your application’s web service requests receive error messages, you can lower usage by optimizing applications to use the web services more efficiently.

Before you begin

Before optimizing your application’s web service usage, check that you’re using the correct service for your use case and the correct Maps APIs license.

Validate your use case

Google Maps Platform web services are best for applications that don’t require real-time input from users or when a web browser is not used. For example, you should use web services if your application uses a dataset that is independent of user input—for example, a fixed set of addresses on a real estate web site that needs to be geocoded.

Note that with web services, the queries-per-second (QPS) limit applies to your Premium Plan license, regardless of how many IP addresses requests are sent from.

On the other hand, the client-side services available with the Maps JavaScript API are rate limited per browser session, so that requests are distributed across all your users and scale as the number of users grows. Therefore, client-side services are best for applications that geocode address input from users in real time, such as a store locator that searches for stores near a user’s home address.

For a more detailed discussion on when to use web services, see Geocoding Strategies. Although specific to geocoding, the recommendations in this document apply to all web services, explaining when you should use server-side web services or their client-side equivalents.

How to optimize web service usage

To use web services more efficiently, you can lower usage by sending requests only when necessary and spreading usage evenly to keep it under the limits.

Cache results

Section 3.2.4.b of the Google Maps Platform Terms of Service specifies that you can temporarily cache Google Maps data for a period of up to 30 days to improve performance of your application. By caching web service responses, your application can avoid sending duplicate requests over short periods of time.

To increase cache hit rates, make sure you normalize latitude/longitude (lat/long) coordinates by rounding to 6 decimal places, which provides a precision of about 11 centimeters around the equator. If you add more decimals, results from web services won’t change but cache hit rates will decrease.

Throttle requests

To avoid exceeding usage limits, you can configure your application to throttle requests, by placing them in a queue that keeps track of when the requests are sent. If your application receives one additional request beyond the QPS limit, it should check the timestamp of the first request and wait 1 second.

Even with throttling, applications might still receive responses with the status code OVER_QUERY_LIMIT. Configure your application to insert a small delay (20 ms) and try again if it receives such response.