Google 地图 api 自动完成 - 获取一个城市(或几个城市)的位置

Google maps api autocomplete - get location in one city (or few cities)

我已经 Google 找到了,但我没有找到任何答案。是否可以在 Google 地图自动完成结果中仅获取给定城市中的位置?例如,我想要巴黎和纽约市的所有地址,并排除所有其他结果。我没有在文档中找到这个,我可以按国家/地区过滤结果,但我想按城市过滤。如果我的回调函数 return false?

好吧,如果您想设置 region/location bias;您可以通过以下方式使自动完成结果偏向于大致位置或区域:

Set the bounds on creation of the Autocomplete object.
Change the bounds on an existing Autocomplete.
Set the bounds to the map's viewport.
Restrict the search to the bounds.
Restrict the search to a specific country.

有关详细信息,请参阅 Docs

不,这目前不可能,但有 long-standing feature request on the Public Issue Tracker to have the Places Autocomplete's componentRestrictions option be more similar to the same option for the Geocoding Service,因为自动完成仅支持国家(最多 5 个),而地理编码器允许其他组件过滤器,包括 city/locality.您可能希望为问题加注星标以获取更新并表现出对此正在实施的兴趣。