简体   繁体   中英

How to get search autocomplete in Google Places API for Android only by specific region type (country, sublocality etc.)?

I'm trying to create autocomplete searching in my Android app via Google Places API for Android. Main goal is to search only by cities and administrative_area_level_1 , but unfortunately I can't find way to create such AutocompleteFilter . Maybe someone had the same problem?

I'm using Play Services ver. 9.8.0

 StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
        sb.append("?key=" + API_KEY);
        sb.append("&components=country:IN");
        sb.append("&input=" + URLEncoder.encode(input, "utf8"));

There isn't a single filter that does exactly what you want, unfortunately. AutocompleteFilter allows you to specify TYPE_FILTER_REGIONS or TYPE_FILTER_CITIES but these can't be combined in a single filter. Also, TYPE_FILTER_REGIONS can return things other than administrative_area_level_1 .

One solution might be to make two autocomplete request in parallel with the two different filter settings and combine the results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM