Google 地点 API setFields 和 getDetails

Google Places API setFields AND getDetails

google places api docs 明确声明:"IMPORTANT: To avoid paying for data that you don't need, be sure to use Autocomplete.setFields() to specify only the place data that you will use." 但是当我调用 getDetails() 方法时(请参见下面的通用 y 形式),我指定了我的 fields,这是 setFields() 设置的。

我想我基本上是通过 getDetails() 方法设置它们,但考虑到文档中的谨慎,除了我们需要的之外,我也不想让任何人感到意外。我试图在文档中找到明确的答案,但我还没有找到。我希望这里有人从经验中知道或者对文档有更好的运气。谢谢!

    const placesService = new google.maps.places.PlacesService(myField);
    placesService.getDetails(
      {
        fields: ['address_components'],
        placeId: result.place_id,
        sessionToken: token,
      },
      details => this.updateMethod(details.address_components),
    );

Autocomplete.setFields在实现Places Autocomplete Widget which will constrain the succeeding Places Details request to specific fields only when a user selects a place from the suggestions. Check out the example here时使用。

但是,对于您给出的示例代码,我可以看出您是直接使用Places Service to get the details of a place given a Place ID and not from the Autocomplete Widget suggestions. With this, you can just set the fields in the request parameter of the getDetails(request, callback) method which is what you have correctly done in your code. See this example

希望对您有所帮助!