Google Maps Autocomplete WITHOUT Atmosphere Data

核能气质少年 提交于 2019-11-30 09:18:02

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!