从 google 个位置 api 保存和刷新 place_id 的最佳做法是什么?

What is the best practice for saving and refreshing a place_id from google places api?

在 google 上放置文档说:

"Best practise is to refresh your stored place IDs periodically, after 100 days for example. One strategy is to store the original request that returned each place ID. If a place ID becomes invalid, you can re-issue that request to get fresh results. These results may or may not include the original place."

我正在使用 AutocompleteService.getPlacePredictions 检索地点并保存所选地点的 place_id。

我应该为 place_id 的以后 "refreshing" 保存哪个其他字段以及 "refreshing" 单个 place_id 的最佳方法是什么? (我假设不使用 AutocompleteService)

正如您问题中发布的文档中所述,您可以存储返回 place_id 的请求。因此,一种方法是保存用户输入(用于请求自动完成的文本)以提供 place_id.

另一种方法是保存 "description" 字段(在预测中)用于给出 place_id。如文档中所述 "description is the matched prediction" 并且因为与 place_id 相关联。您可以确定此字段与该地点相关联。

保存描述似乎可行,但在某些(非常具体的)情况下,它们也可能在数据库中发生更改,从而导致结果不准确。

最好建议保存输入文本(用于自动完成请求),但这需要是一个强查询。我的意思是:

例如,如果你想为时代广场保存 place_id,也许输入 "times" 你已经得到了它的预测,但 "times" 本身并不强查询,所以最好保存 "times square".

并确保您保存的查询始终为您提供您想要的位置作为第一个预测。