Search in sources :

Example 1 with PlaceRequest

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

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

the class ResultListActivity method onListItemClick.

/* Retrieve details of the place selected */
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    DiscoveryResult result = MapFragmentView.s_ResultList.get(position);
    if (result.getResultType() == DiscoveryResult.ResultType.PLACE) {
        /* Fire the PlaceRequest */
        PlaceLink placeLink = (PlaceLink) result;
        PlaceRequest placeRequest = placeLink.getDetailsRequest();
        placeRequest.execute(m_placeResultListener);
    } else if (result.getResultType() == DiscoveryResult.ResultType.DISCOVERY) {
        /*
             * Another DiscoveryRequest object can be obtained by calling DiscoveryLink.getRequest()
             */
        Toast.makeText(this, "This is a DiscoveryLink result", Toast.LENGTH_SHORT).show();
    }
}
Also used : PlaceLink(com.here.android.mpa.search.PlaceLink) PlaceRequest(com.here.android.mpa.search.PlaceRequest) DiscoveryResult(com.here.android.mpa.search.DiscoveryResult)

Example 3 with PlaceRequest

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

the class ResultListActivity method onListItemClick.

/* Retrieve details of the place selected */
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    DiscoveryResult result = MapFragmentView.s_discoverResultList.get(position);
    if (result.getResultType() == DiscoveryResult.ResultType.PLACE) {
        /* Fire the PlaceRequest */
        PlaceLink placeLink = (PlaceLink) result;
        PlaceRequest placeRequest = placeLink.getDetailsRequest();
        placeRequest.execute(m_placeResultListener);
    } else if (result.getResultType() == DiscoveryResult.ResultType.DISCOVERY) {
        /*
             * Another DiscoveryRequest object can be obtained by calling DiscoveryLink.getRequest()
             */
        Toast.makeText(this, "This is a DiscoveryLink result", Toast.LENGTH_SHORT).show();
    }
}
Also used : PlaceLink(com.here.android.mpa.search.PlaceLink) PlaceRequest(com.here.android.mpa.search.PlaceRequest) DiscoveryResult(com.here.android.mpa.search.DiscoveryResult)

Aggregations

PlaceRequest (com.here.android.mpa.search.PlaceRequest)3 DiscoveryResult (com.here.android.mpa.search.DiscoveryResult)2 PlaceLink (com.here.android.mpa.search.PlaceLink)2 Intent (android.content.Intent)1 AutoSuggest (com.here.android.mpa.search.AutoSuggest)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 ErrorCode (com.here.android.mpa.search.ErrorCode)1 Place (com.here.android.mpa.search.Place)1 TextAutoSuggestionRequest (com.here.android.mpa.search.TextAutoSuggestionRequest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1