简体   繁体   English

Android:首先在附近放置选择器搜索

[英]Android: Place picker search nearby first

I am using Google's Place Picker to get the location (either the current location or the location of the place he searches for). 我正在使用Google的地方选择器来获取位置(当前位置或他搜索的地点的位置)。 Everything works very fine, but have the following problem. 一切都很好,但有以下问题。

Suppose I am in Bangalore, India, when I search for a hotel, say "Leela Palace" when I type "Lee" the AutoComplete displays "Leeds, United Kingdom", "Leensburg, VA United States" etc... 假设我在印度班加罗尔,当我搜索酒店时,当我输入“Lee”时说“Leela Palace”,AutoComplete显示“Leeds,United Kingdom”,“Leensburg,VA United States”等...

How can we make the autocomplete first search the nearby places first rather than other countries. 我们如何让自动填充首先搜索附近的地方而不是其他国家。

Apply a filter first: 首先应用过滤器:

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder(). setTypeFilter(Place.TYPE_COUNTRY).setCountry("IN").build();//results are filtered within India

Now pass this filter to the Intent: 现在将此过滤器传递给Intent:

PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) .setFilter(typeFilter) .build(this);

Use this. 用这个。

PlaceAutocompleteFragment placeAutocompleteFragment = (PlaceAutocompleteFragment) getActivity().getFragmentManager().findFragmentById(R.id.pafSetLocation);

    AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
            .build();
    placeAutocompleteFragment.setFilter(typeFilter);

You can also visit https://developers.google.com/places/web-service/search for more help. 您还可以访问https://developers.google.com/places/web-service/search获取更多帮助。

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

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