google-maps - 新的 Places API Billing 如何处理 Session?

标签 google-maps google-places-api

新的 Places API Billing 定义了用于合并自动完成和地点详细信息请求的 session ,但文档只是说 API 将在几分钟内合并具有相同 session token 的请求。

我觉得这很模糊!

我们是否必须生成新的 session token ,或者我们是否可以重复使用相同的 session token 并且 API 无论如何都会在时间窗口内对它们进行分组?

我们是否必须了解 session token 的生命周期?

session token 可以是任何类型的字符串吗?

最佳答案

Google 拥有所有这些答案,但分布在许多不同的地方并且很难找到。要回答您的所有 3 个问题:

Do we have to generate new Session Tokens or can we reuse the same and the API will group them anyway within time-windows?

session token 不能从一个 session 重用到另一个 session 。

Do we have to be aware of the lifespan of the Session Tokens?

session 在用户开始输入时开始,在他们选择一个位置并且您调用详细信息 API 时结束。一旦发生这种情况,您必须为每次新的自动完成 API 调用生成一个新的 session token 。

Can the Session Tokens be any kind of string?

Google Places API 提供了一个您可以使用但并非必须使用的类。 Google 提供的类称为 AutocompleteSessionToken它可以像这样使用:

var token = new google.maps.places.AutocompleteSessionToken()

但您也可以使用自己的字符串。参见 Google's recommendation

所有这些信息都直接来自 Google 文档,见下文:

Place Autocomplete uses session tokens to group the query and selection phases of a user autocomplete search into a discrete session for billing purposes. The session begins when the user starts typing a query, and concludes when they select a place. Each session can have multiple queries, followed by one place selection. Once a session has concluded, the token is no longer valid; your app must generate a fresh token for each session. We recommend using session tokens for all autocomplete sessions. If the sessiontoken parameter is omitted, or if you reuse a session token, the session is charged as if no session token was provided (each request is billed separately).

来源:Google Documentation

关于google-maps - 新的 Places API Billing 如何处理 Session?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54432571/

相关文章:

javascript - setTimeout 在循环中检查边界变化

android - 如何从数组列表中动态添加多段线

android - 使用 Google Place 自动完成功能限制国家/地区的结果?

google-maps - Google Places API - 谷歌如何确定城市/县的纬度/经度?

javascript - Sencha Touch - Map.Geo = null

javascript - 将图像放在 Google map 上

javascript - 谷歌地图 API (JS) : check if I reached my destination

google-places-api - Google Places AutocompleteService按国家/地区过滤

javascript - Google Places 自动完成 API 多个实例

ios - Google 自动完成功能调用后崩溃