最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Limit google places autocomplete results to only display state or country or both - Stack Overflow

programmeradmin1浏览0评论

The api for this is the 'types' parameter.

Documented here

Ideally I'd pass ['administrative_area_level_1','country'] but it doesn't show any results.

Passing only one of these types doesn't show any results either.

The best match is ['(regions)'], but besides countries and states, it finds city names as well, which are irrelevant in my use case.

How can this be solved?

Thanks

The api for this is the 'types' parameter.

Documented here https://developers.google./places/supported_types#table3

Ideally I'd pass ['administrative_area_level_1','country'] but it doesn't show any results.

Passing only one of these types doesn't show any results either.

The best match is ['(regions)'], but besides countries and states, it finds city names as well, which are irrelevant in my use case.

How can this be solved?

Thanks

Share Improve this question asked Jun 14, 2017 at 3:31 usermaxusermax 1431 silver badge11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Unfortunately, for autoplete, only the geocode, address, establishment, (regions), and (cities) types can be used.

The only way this problem can really be solved is by using the HTTP API and creating your own UI for the autoplete box. This link can be used for the api: https://maps.googleapis./maps/api/place/autoplete/json?input=QUERY&key=API_KEY&types=(regions). The result is returned in a JSON object, and each item has a types field consisting of an array of the types applicable to the location. The type at index 0 is the one you're interested in. It's usually something like country, or administrative_area_level_1.

发布评论

评论列表(0)

  1. 暂无评论