How to Use google places api in android with restrict particular place?

1.6k Views Asked by At

Hey Guys i basically i want to create one application that have Autocomplete TextView and show place according user search i just restrict user show only india's city name not other. can any one know ?

3

There are 3 best solutions below

0
On BEST ANSWER

To search places bounded to only India , you can use setBoundsBias() in your code.Google now provides Autocomplete widget which makes things even simpler. Please see this link: https://developers.google.com/places/android-api/autocomplete

0
On

This worked for me

try {
                AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
                        .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
                        .setCountry("au")
                        .build();
                Intent intent = new PlaceAutocomplete.IntentBuilder
                        (PlaceAutocomplete.MODE_FULLSCREEN)
                        .setFilter(typeFilter)                         
                        .build(ProfileActivity.this);
                startActivityForResult(intent, REQUEST_SELECT_PLACE);
            } catch (GooglePlayServicesRepairableException |
                    GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            }
0
On

Create a filter and setCountry as India in the filter and set the filter in the PlaceAutoComplete fragment or intent.

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
    .setCountry("IN")
    .build();
autocompleteFragment.setFilter(typeFilter);