How to set “Types” in Google Place PlacePicker in Android?

孤街浪徒 提交于 2019-12-19 05:57:06

问题


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.
}


来源:https://stackoverflow.com/questions/30852349/how-to-set-types-in-google-place-placepicker-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!