Search in sources :

Example 1 with ObjectType

use of net.osmand.search.core.ObjectType in project Osmand by osmandapp.

the class ExternalApiHelper method runSearch.

public static void runSearch(final OsmandApplication app, String searchQuery, int searchType, double latitude, double longitude, int radiusLevel, int totalLimit, final OsmandAidlApi.SearchCompleteCallback callback) {
    if (radiusLevel < 1) {
        radiusLevel = 1;
    } else if (radiusLevel > MAX_DEFAULT_SEARCH_RADIUS) {
        radiusLevel = MAX_DEFAULT_SEARCH_RADIUS;
    }
    if (totalLimit <= 0) {
        totalLimit = -1;
    }
    final int limit = totalLimit;
    final SearchUICore core = app.getSearchUICore().getCore();
    core.setOnResultsComplete(new Runnable() {

        @Override
        public void run() {
            List<AidlSearchResultWrapper> resultSet = new ArrayList<>();
            SearchUICore.SearchResultCollection resultCollection = core.getCurrentSearchResult();
            int count = 0;
            for (net.osmand.search.core.SearchResult r : resultCollection.getCurrentSearchResults()) {
                String name = QuickSearchListItem.getName(app, r);
                String typeName = QuickSearchListItem.getTypeName(app, r);
                AidlSearchResultWrapper result = new AidlSearchResultWrapper(r.location.getLatitude(), r.location.getLongitude(), name, typeName, r.alternateName, new ArrayList<>(r.otherNames));
                resultSet.add(result);
                count++;
                if (limit != -1 && count >= limit) {
                    break;
                }
            }
            callback.onSearchComplete(resultSet);
        }
    });
    SearchSettings searchSettings = new SearchSettings(core.getSearchSettings()).setRadiusLevel(radiusLevel).setEmptyQueryAllowed(false).setSortByName(false).setOriginalLocation(new LatLon(latitude, longitude)).setTotalLimit(totalLimit);
    List<ObjectType> searchTypes = new ArrayList<>();
    if ((searchType & SearchParams.SEARCH_TYPE_POI) != 0) {
        searchTypes.add(POI);
    }
    if ((searchType & SearchParams.SEARCH_TYPE_ADDRESS) != 0) {
        searchTypes.add(CITY);
        searchTypes.add(VILLAGE);
        searchTypes.add(POSTCODE);
        searchTypes.add(STREET);
        searchTypes.add(HOUSE);
        searchTypes.add(STREET_INTERSECTION);
    }
    searchSettings = searchSettings.setSearchTypes(searchTypes.toArray(new ObjectType[0]));
    core.search(searchQuery, false, null, searchSettings);
}
Also used : AidlSearchResultWrapper(net.osmand.aidl.AidlSearchResultWrapper) ArrayList(java.util.ArrayList) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) ObjectType(net.osmand.search.core.ObjectType) SearchUICore(net.osmand.search.SearchUICore) SearchSettings(net.osmand.search.core.SearchSettings) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AidlSearchResultWrapper (net.osmand.aidl.AidlSearchResultWrapper)1 FavouritePoint (net.osmand.data.FavouritePoint)1 LatLon (net.osmand.data.LatLon)1 SearchUICore (net.osmand.search.SearchUICore)1 ObjectType (net.osmand.search.core.ObjectType)1 SearchSettings (net.osmand.search.core.SearchSettings)1