I am currently using the Google Maps Places Autocomplete Javascript API to let users select a location by searching for the address or establishment name. Example code:
You can use AutocompleteOptions object in order to define fields that you want to see in details responses. AutocompleteOptions has a fields
property
fields - Fields to be included for the Place in the details response when the details are successfully retrieved. For a list of fields see PlaceResult. Nested fields can be specified with dot-paths (for example, "geometry.location").
So, you can change autocomplete initialization to the following form
autocomplete = new google.maps.places.Autocomplete(input, {
fields: ["name", "geometry.location", "place_id", "formatted_address"]
});
I hope this helps!
https://developers.google.com/places/web-service/usage-and-billing
A Places Details request generates Data SKUs (Basic, Contact, and/or Atmosphere) – depending on the fields that are specified in the request. If you do not specify fields in the Place Details request, all Data SKUs are triggered (Basic, Contact, and Atmosphere). To avoid paying for data that you don't need, call Autocomplete.setFields() to specify only the place data that you will use.
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.setFields(['address_components', 'formatted_address', 'geometry', 'icon', 'name']);
You can check all the fields here
Just call setField()
after instantiating the autocomplete object, for example:
autocomplete.setFields(['address_components', 'formatted_address', 'geometry', 'icon', 'name']);
Nice try Google. After the hefty price change, instead of deprecating the APIs and make it obvious the requests will cost a fortune, they silently allowed the current code to request everything, thus profiting from the sudden charge increase.
Nice move but it's already backfiring: Will remove all the Google services from my systems. OpenStreetMap and ArcGIS and Mapbox are much more affordable