How to set “Types” in Google Place PlacePicker in

2020-03-12 08:26发布

问题:

In the new google places API, they come with a new feature called PlacePicker. It's a simple activity to select a place of the list/map of places they have.

In the Places API we can give a types list, to receive only places of those specific types.

I'm building an app that uses only "establishment" places.

But this activity shows all the places, including a lot of places that i do not need (libraries, schools, gas ...)

There is a way to set the types of the PlacePicker?

Reading the API docs doesn't say nothing about.

回答1:

Currently it seems not to be possible. There is an open feature request, however. Please star it.



回答2:

Apparently right now, android have documentation to do some filtering using AutocompleteFilter class. The documentation of Place Autocomplete

example of usage :

//set boundary on build place picker fragment
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
builder.setLatLngBounds(bounds);

 //set filter type by country 'malaysia'
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
    .setTypeFilter(1013) //set point of interest
    .setCountry("MY")
    .build();

try {
    Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
        .setFilter(typeFilter)
        .build(MainActivity.this);

    startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);        
} catch (GooglePlayServicesRepairableException e) {
    // TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
    // TODO: Handle the error.
}