Search in sources :

Example 1 with AddressFilter

use of com.here.android.mpa.search.AddressFilter in project here-android-sdk-examples by heremaps.

the class MapFragmentView method doSearch.

private void doSearch(String query) {
    setSearchMode(true);
    /*
         Creates new TextAutoSuggestionRequest with current map position as search center
         and selected collection size with applied filters and chosen locale.
         For more details how to use TextAutoSuggestionRequest
         please see documentation for HERE Mobile SDK for Android.
         */
    TextAutoSuggestionRequest textAutoSuggestionRequest = new TextAutoSuggestionRequest(query);
    textAutoSuggestionRequest.setSearchCenter(m_map.getCenter());
    textAutoSuggestionRequest.setCollectionSize(Integer.parseInt(m_collectionSizeTextView.getText().toString()));
    applyResultFiltersToRequest(textAutoSuggestionRequest);
    Locale locale = getSelectedLocale();
    if (locale != null) {
        textAutoSuggestionRequest.setLocale(locale);
    }
    String countryCode = getSelectedCountryCode();
    if (!TextUtils.isEmpty(countryCode)) {
        AddressFilter addressFilter = new AddressFilter();
        // Also available filtering by state code, county, district, city and zip code
        addressFilter.setCountryCode(countryCode);
        textAutoSuggestionRequest.setAddressFilter(addressFilter);
    }
    /*
           The textAutoSuggestionRequest returns its results to non-UI thread.
           So, we have to pass the UI update with returned results to UI thread.
         */
    textAutoSuggestionRequest.execute(new ResultListener<List<AutoSuggest>>() {

        @Override
        public void onCompleted(final List<AutoSuggest> autoSuggests, ErrorCode errorCode) {
            if (errorCode == errorCode.NONE) {
                processSearchResults(autoSuggests);
            } else {
                handleError(errorCode);
            }
        }
    });
}
Also used : Locale(java.util.Locale) TextAutoSuggestionRequest(com.here.android.mpa.search.TextAutoSuggestionRequest) AddressFilter(com.here.android.mpa.search.AddressFilter) ArrayList(java.util.ArrayList) List(java.util.List) AutoSuggest(com.here.android.mpa.search.AutoSuggest) ErrorCode(com.here.android.mpa.search.ErrorCode)

Aggregations

AddressFilter (com.here.android.mpa.search.AddressFilter)1 AutoSuggest (com.here.android.mpa.search.AutoSuggest)1 ErrorCode (com.here.android.mpa.search.ErrorCode)1 TextAutoSuggestionRequest (com.here.android.mpa.search.TextAutoSuggestionRequest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1