简体   繁体   English

如何在Android中使用Google Places API限制特定位置?

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

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. 嗨,我基本上我想创建一个具有Autocomplete TextView并根据用户搜索显示位置的应用程序,我只是限制用户仅显示印度的城市名称,而不能显示其他城市。 can any one know ? 有人知道吗?

To search places bounded to only India , you can use setBoundsBias() in your code.Google now provides Autocomplete widget which makes things even simpler. 要搜索仅限于印度的地点,您可以在代码中使用setBoundsBias() 。Google现在提供了自动填充小部件,这使事情变得更加简单。 Please see this link: https://developers.google.com/places/android-api/autocomplete 请查看此链接: https : //developers.google.com/places/android-api/autocomplete

Create a filter and setCountry as India in the filter and set the filter in the PlaceAutoComplete fragment or intent. 创建一个过滤器,并在过滤器中将setCountry设置为India,然后在PlaceAutoComplete片段或intent中设置该过滤器。

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

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();
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM