androidgoogle-mapsgoogle-places-api

Google Maps - Places API: Why can't I combine ADDRESS and ESTABLISHMENT in setTypesFilter()?


I'm using the Places SDK for Android and trying to get both addresses and business names in autocomplete predictions. Since setTypeFilter() was deprecated, I switched to setTypesFilter() as recommended.

I expected that with setTypesFilter() I could pass multiple place types in one request, like this:

FindAutocompletePredictionsRequest.builder()
            .setCountries("US")
            .setTypesFilter(listOf(PlaceTypes.ADDRESS, PlaceTypes.ESTABLISHMENT))
            .setSessionToken(token)
            .setQuery(query)
            .build()

But when I run this, I get the following error:

Failure(com.google.android.gms.common.api.ApiException: 9012: address cannot be mixed with other types.)

So even though setTypesFilter() supports a list, it seems there are still restrictions on which types can be combined..

My questions: Is it officially unsupported to combine PlaceTypes.ADDRESS with other types like PlaceTypes.ESTABLISHMENT? If so, what’s the best practice to retrieve both address and business predictions for the same user query?


Solution

  • What you’re seeing is exactly how the Places SDK for Android is designed to work.

    You cannot combine the ADDRESS and ESTABLISHMENT types, you must use only one. The Place Types and Filter results by place types or type collection documentation clearly state:

    "Only a single type from Table 3 is allowed in the request. If you do specify a value from Table 3, you cannot specify a value from Table 1 or Table 2."

    The Reference for setTypesFilter reiterates this:

    "The type collections specified in table 3 must be passed in as solo entries and cannot be combined with any other entries from table 1 or 2."

    As a best practice, filter predictions using a place’s primary types, since each place can have only a single primary type. If you choose a type from Table 3, don’t mix it with others or you’ll get an error such as what you described:

    Failure(com.google.android.gms.common.api.ApiException: 9012: address cannot be mixed with other types.)