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

前端 未结 2 511
死守一世寂寞
死守一世寂寞 2021-01-12 02:01

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

2条回答
  •  悲&欢浪女
    2021-01-12 02:29

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

提交回复
热议问题