This API seems to be fairly new so there aren't many questions about it here, nor many tutorials.
I followed Google's tutorial and got the Autocomplete Android api working in my app. I'm now trying to use the AutocompleteFilter to restrict my results to a certain region or certain types of places.
There seems to be little to no documentation for a beginner like me explaining what to do.
The AutocompleteFilter requires a Collection object. How do I change the the following values into integers?
Depending on your requirement, an
AutocompleteFilter
can be built. This filter can then be applied to theIntentBuilder
by usingsetFilter()
.For example:
If you want to restrict the results to a particular country, you could do that by:
If you want to restrict the results to a particular place type, you could do that in a similar way by changing the Filter as:
Problem was solved by a Google employee himself whom I contacted via our Maps for Work support portal.
Here's a list of Place Types with their integer counterparts.
https://developers.google.com/android/reference/com/google/android/gms/location/places/Place
These can be used to filter the Android Place Autocomplete API.
Android Place Autocomplete does not support all the types enumerated by the link provided in the previous answer.
Since v8.4 release, the supported types are provided by AutocompleteFilter as documented here
I cannot comment yet so I add it here a warning for the answer above:
Not all constant from Place are available for filtering with AutocompleteFilter, only two are available on Android:
Place.TYPE_GEOCODE
andPlace.TYPE_ESTABLISHMENT
('address' appear in documentation but not as constant inPlace
)If any other constant (e.g.
Place.TYPE_LOCALITY
) are used the request will result in this confusing status error: