Field Masks not working on Google Geocoding API

172 Views Asked by At

Following the official Google developer doc here.

I am trying to hit following API:

https://maps.googleapis.com/maps/api/geocode/json?address=bangalore&key=MY_KEY&fields=formatted_address,geometry/location

By default, this API return lot of fields in response as mentioned in the doc here.

Even after using fields query-param, I see all the data is being returned.

I only need two fields for cost-optimization, as mentioned in my URL formatted_address,geometry/location.

Even official docs suggest to use field-masks as described here.

Does anyone know what am I missing here?

1

There are 1 best solutions below

0
Yrll On

Geocoding API does not support field masking

The API you actually linked that supported field masking is Places API Place Autocomplete. Field masking is only available in Places API.

There's no part in the official Geocoding API documentation that says that it supports field masking. While it does in the Places API as you have linked.

Google Maps API uses a pay-as-you-go pricing model. The Google Maps Platform APIs and SDKs are billed by SKU. Usage is tracked for each SKU, and any API or SDK may have more than one product SKU. Cost is calculated by

SKU usage × Price per each use

Geocoding API only have one SKU, wherein you get charged per request no matter how you do it. See: https://developers.google.com/maps/documentation/geocoding/usage-and-billing#geocoding

While the Places API have three Places Data SKUs, and these are:

  1. Basic Data
  2. Contact Data
  3. and Atmosphere Data

Data SKUs are always charged in addition to the base SKU for the request triggering them. For example, a Place Details request including Basic Data fields will be charged both under the Basic Data SKU and the Place Details SKU.

ref: https://developers.google.com/maps/documentation/places/web-service/usage-and-billing#data-skus

In short, you can't reduce cost in Geocoding API since it is being billed as a single SKU and it does not have a fields parameter to be used. And you can only use field masking if you're using Places API.

I would suggest that you read more about it in the documentation, or if you have any queries about the APIs, feel free to file a support case throught his link: https://developers.google.com/maps/support#contact-maps-support

I hope this helps!