首页 > 解决方案 > 如何在 Google Places Autocomplete API 中获取位置

问题描述

因此,我使用 Google Places API 来搜索地点并从地点获取数据。

我的目标是通过名称获取位置(几何),独立于我的位置,在世界各地提供自动完成建议。这些是我测试的选项:

选项1

我已经在使用“findplacefromtext”:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input={name of place}&inputtype=textquery&fields={fields}&language=en&key={key}"

https://developers.google.com/places/web-service/search#FindPlaceRequests

它有效,但我只得到一个结果。我想在该请求中获得自动完成建议。是否可以在此请求中返回 1 个以上的结果?

选项 2

因此,在我的第二种方法中,我尝试使用 AutoComplete 请求“autocomplete/json”:

https://maps.googleapis.com/maps/api/place/autocomplete/json?key={key}&input={text}&language=en

https://developers.google.com/places/web-service/autocomplete

这正是我正在寻找的,但它缺少位置和地点信息。它包含“place_id”,带有“place_id”我可以发出第二个请求,返回我需要的所有地点数据,但总共有 2 个请求,而不是 1 个。如果我有 15 个结果,我将拥有使用 15 个请求(Place Detail Request)

https://developers.google.com/places/web-service/details

是否可以在自动完成请求中返回地点信息,而无需提出地点详细信息请求?

标签: google-apigoogle-places-apigoogle-placesgoogleplacesautocomplete

解决方案


地方自动填充目前不返回或支持比此处指示的详细的信息。如果您有兴趣拥有此功能,可以在 Google 的Public Issue Tracker中提交功能请求,供 Google 产品团队评估。


推荐阅读