Search in sources :

Example 1 with ErrorCode

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

the class MapFragmentView method handleSelectedAutoSuggest.

private void handleSelectedAutoSuggest(AutoSuggest autoSuggest) {
    int collectionSize = Integer.parseInt(m_collectionSizeTextView.getText().toString());
    switch(autoSuggest.getType()) {
        case PLACE:
            /*
                 Gets initialized PlaceRequest with location context that allows retrieving details
                 about the place on the selected location.
                 */
            AutoSuggestPlace autoSuggestPlace = (AutoSuggestPlace) autoSuggest;
            PlaceRequest detailsRequest = autoSuggestPlace.getPlaceDetailsRequest();
            detailsRequest.execute(new ResultListener<Place>() {

                @Override
                public void onCompleted(Place place, ErrorCode errorCode) {
                    if (errorCode == ErrorCode.NONE) {
                        handlePlace(place);
                    } else {
                        handleError(errorCode);
                    }
                }
            });
            break;
        case SEARCH:
            /*
                 Gets initialized AutoSuggestSearch with location context that allows retrieving
                 DiscoveryRequest for further processing as it is described in
                 the official documentation.
                 Some example of how to handle DiscoveryResultPage you can see in
                 com.here.android.example.autosuggest.ResultListActivity
                 */
            AutoSuggestSearch autoSuggestSearch = (AutoSuggestSearch) autoSuggest;
            DiscoveryRequest discoverRequest = autoSuggestSearch.getSuggestedSearchRequest();
            discoverRequest.setCollectionSize(collectionSize);
            discoverRequest.execute(new ResultListener<DiscoveryResultPage>() {

                @Override
                public void onCompleted(DiscoveryResultPage discoveryResultPage, ErrorCode errorCode) {
                    if (errorCode == ErrorCode.NONE) {
                        s_discoverResultList = discoveryResultPage.getItems();
                        Intent intent = new Intent(m_activity, ResultListActivity.class);
                        m_activity.startActivity(intent);
                    } else {
                        handleError(errorCode);
                    }
                }
            });
            break;
        case QUERY:
            /*
                 Gets TextAutoSuggestionRequest with suggested autocomplete that retrieves
                 the collection of AutoSuggest objects which represent suggested.
                 */
            final AutoSuggestQuery autoSuggestQuery = (AutoSuggestQuery) autoSuggest;
            TextAutoSuggestionRequest queryReqest = autoSuggestQuery.getRequest(getSelectedLocale());
            queryReqest.setCollectionSize(collectionSize);
            queryReqest.execute(new ResultListener<List<AutoSuggest>>() {

                @Override
                public void onCompleted(List<AutoSuggest> autoSuggests, ErrorCode errorCode) {
                    if (errorCode == ErrorCode.NONE) {
                        processSearchResults(autoSuggests);
                        m_searchView.setOnQueryTextListener(null);
                        m_searchView.setQuery(autoSuggestQuery.getQueryCompletion(), false);
                        m_searchView.setOnQueryTextListener(m_searchListener);
                    } else {
                        handleError(errorCode);
                    }
                }
            });
            break;
        // Do nothing.
        case UNKNOWN:
        default:
    }
}
Also used : PlaceRequest(com.here.android.mpa.search.PlaceRequest) AutoSuggestQuery(com.here.android.mpa.search.AutoSuggestQuery) TextAutoSuggestionRequest(com.here.android.mpa.search.TextAutoSuggestionRequest) AutoSuggestSearch(com.here.android.mpa.search.AutoSuggestSearch) Intent(android.content.Intent) AutoSuggestPlace(com.here.android.mpa.search.AutoSuggestPlace) DiscoveryResultPage(com.here.android.mpa.search.DiscoveryResultPage) ArrayList(java.util.ArrayList) List(java.util.List) ErrorCode(com.here.android.mpa.search.ErrorCode) DiscoveryRequest(com.here.android.mpa.search.DiscoveryRequest) AutoSuggest(com.here.android.mpa.search.AutoSuggest) Place(com.here.android.mpa.search.Place) AutoSuggestPlace(com.here.android.mpa.search.AutoSuggestPlace)

Example 2 with ErrorCode

use of com.here.android.mpa.search.ErrorCode 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)

Example 3 with ErrorCode

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

the class MainView method triggerGeocodeRequest.

private void triggerGeocodeRequest() {
    m_resultTextView.setText("");
    /*
         * Create a GeocodeRequest object with the desired query string, then set the search area by
         * providing a GeoCoordinate and radius before executing the request.
         */
    String query = "4350 Still Creek Dr,Burnaby";
    GeocodeRequest geocodeRequest = new GeocodeRequest(query);
    GeoCoordinate coordinate = new GeoCoordinate(49.266787, -123.056640);
    geocodeRequest.setSearchArea(coordinate, 5000);
    geocodeRequest.execute(new ResultListener<List<GeocodeResult>>() {

        @Override
        public void onCompleted(List<GeocodeResult> results, ErrorCode errorCode) {
            if (errorCode == ErrorCode.NONE) {
                /*
                     * From the result object, we retrieve the location and its coordinate and
                     * display to the screen. Please refer to HERE Android SDK doc for other
                     * supported APIs.
                     */
                StringBuilder sb = new StringBuilder();
                for (GeocodeResult result : results) {
                    sb.append(result.getLocation().getCoordinate().toString());
                    sb.append("\n");
                }
                updateTextView(sb.toString());
            } else {
                updateTextView("ERROR:Geocode Request returned error code:" + errorCode);
            }
        }
    });
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) List(java.util.List) ErrorCode(com.here.android.mpa.search.ErrorCode) GeocodeRequest(com.here.android.mpa.search.GeocodeRequest) ReverseGeocodeRequest(com.here.android.mpa.search.ReverseGeocodeRequest) GeocodeResult(com.here.android.mpa.search.GeocodeResult)

Example 4 with ErrorCode

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

the class MainView method triggerRevGeocodeRequest.

private void triggerRevGeocodeRequest() {
    m_resultTextView.setText("");
    /* Create a ReverseGeocodeRequest object with a GeoCoordinate. */
    GeoCoordinate coordinate = new GeoCoordinate(49.25914, -123.00777);
    ReverseGeocodeRequest revGecodeRequest = new ReverseGeocodeRequest(coordinate);
    revGecodeRequest.execute(new ResultListener<Location>() {

        @Override
        public void onCompleted(Location location, ErrorCode errorCode) {
            if (errorCode == ErrorCode.NONE) {
                /*
                     * From the location object, we retrieve the address and display to the screen.
                     * Please refer to HERE Android SDK doc for other supported APIs.
                     */
                updateTextView(location.getAddress().toString());
            } else {
                updateTextView("ERROR:RevGeocode Request returned error code:" + errorCode);
            }
        }
    });
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) ReverseGeocodeRequest(com.here.android.mpa.search.ReverseGeocodeRequest) ErrorCode(com.here.android.mpa.search.ErrorCode) Location(com.here.android.mpa.search.Location)

Aggregations

ErrorCode (com.here.android.mpa.search.ErrorCode)4 List (java.util.List)3 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)2 AutoSuggest (com.here.android.mpa.search.AutoSuggest)2 ReverseGeocodeRequest (com.here.android.mpa.search.ReverseGeocodeRequest)2 TextAutoSuggestionRequest (com.here.android.mpa.search.TextAutoSuggestionRequest)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 AddressFilter (com.here.android.mpa.search.AddressFilter)1 AutoSuggestPlace (com.here.android.mpa.search.AutoSuggestPlace)1 AutoSuggestQuery (com.here.android.mpa.search.AutoSuggestQuery)1 AutoSuggestSearch (com.here.android.mpa.search.AutoSuggestSearch)1 DiscoveryRequest (com.here.android.mpa.search.DiscoveryRequest)1 DiscoveryResultPage (com.here.android.mpa.search.DiscoveryResultPage)1 GeocodeRequest (com.here.android.mpa.search.GeocodeRequest)1 GeocodeResult (com.here.android.mpa.search.GeocodeResult)1 Location (com.here.android.mpa.search.Location)1 Place (com.here.android.mpa.search.Place)1 PlaceRequest (com.here.android.mpa.search.PlaceRequest)1 Locale (java.util.Locale)1