The Places Autocomplete makeover optimization involves two main steps:
- Switch from per-session billing to per-request billing.
- Substitute a Geocoding API request for the Places Details request.
Here are the main considerations for this optimization.
First, do you need to look up businesses by name (the establishment type in Place Autocomplete)? If so, Place Details is the only way to get business results and you should use Place Autocomplete Per-Session.
However, if you only need to look up non-business place types; such as street addresses, postal codes, cities (the geocode, address, (region), or (cities) types in Place Autocomplete)--you may be able to combine Geocoding API with Place Autocomplete Per-Request billing to save cost, depending on your monthly volume.
If your usage is less than 100,000 places per month, per-session pricing is the lowest cost option in the base price tier. Go ahead and use Place Autocomplete Per-Session (and set field filters so you don't get billed for Contact and Atmosphere data).
But if your usage is more than 100,000 places per month, the discounted price tiers change the economics a bit. At higher volumes, Autocomplete Per-Request with Geocoding becomes the lower cost option, if you can keep your Autocomplete-to-Geocodes request ratio low.
- Use the getPlacePredictions() method in the AutocompleteService class to populate suggestions
- When the user selects a prediction, send a request containing the Place ID to the Geocoder class to get the details
Aim for an Autocomplete-to-Geocodes request ratio of 5:1 to keep cost low as your usage grows through the volume tiers. We suggest setting thresholds to limit your Autocomplete request volume:
- Don't start getting predictions until the user has typed a few non-whitespace characters
- Debounce your requests-wait until the user pauses to get a new batch of predictions
Finally, make sure you include the "powered by Google" attribution required by the Places API terms of service.
What about Mobile?
It is possible to use Autocomplete Per-Request with iOS and Android Places Autocomplete. Here's how.
- iOS - in the iOS findAutocompletePredictionsFromQuery method, the Session Token parameter is nullable. A null session token will force per-request billing.
- Android - the FindAutocompletePredictionsRequest object lists the AutocompleteSessionToken as recommended but not required. Omit this token to force per-request billing.
And remember, instead of the Places Details request, make a Geocoding request with place_id as input parameter.
Places API Usage and Billing - About Autocomplete sessions
Article is closed for comments.