use of net.osmand.aidl.AidlSearchResultWrapper 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);
}
use of net.osmand.aidl.AidlSearchResultWrapper in project Osmand by osmandapp.
the class ExternalApiHelper method searchAndNavigate.
public static void searchAndNavigate(@NonNull MapActivity mapActivity, @NonNull final LatLon searchLocation, @Nullable final LatLon from, @Nullable final PointDescription fromDesc, @NonNull final ApplicationMode mode, @NonNull final String searchQuery, final boolean showSearchResults, final boolean checkLocationPermission) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
OsmandApplication app = mapActivity.getMyApplication();
if (showSearchResults) {
RoutingHelper routingHelper = app.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(from, fromDesc);
} else {
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
TargetPointsHelper targets = app.getTargetPointsHelper();
targets.setStartPoint(from, false, fromDesc);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}
mapActivity.showQuickSearch(ShowQuickSearchMode.DESTINATION_SELECTION_AND_START, true, searchQuery, searchLocation);
} else {
ProgressDialog dlg = new ProgressDialog(mapActivity);
dlg.setTitle("");
dlg.setMessage(mapActivity.getString(R.string.searching_address));
dlg.show();
final WeakReference<ProgressDialog> dlgRef = new WeakReference<>(dlg);
runSearch(app, searchQuery, SearchParams.SEARCH_TYPE_ALL, searchLocation.getLatitude(), searchLocation.getLongitude(), 1, 1, new OsmandAidlApi.SearchCompleteCallback() {
@Override
public void onSearchComplete(final List<AidlSearchResultWrapper> resultSet) {
final MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
ProgressDialog dlg = dlgRef.get();
if (dlg != null) {
dlg.dismiss();
}
if (resultSet.size() > 0) {
final AidlSearchResultWrapper res = resultSet.get(0);
LatLon to = new LatLon(res.getLatitude(), res.getLongitude());
PointDescription toDesc = new PointDescription(PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName());
startNavigation(mapActivity, from, fromDesc, to, toDesc, mode, checkLocationPermission);
} else {
mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found));
}
}
});
}
}
});
}
}
Aggregations