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);
}
Aggregations