/// <summary> /// Queries the Bing Maps Service with a given search query, confidence and userLocation and returns a list of locations that match the query /// </summary> /// <param name="query">Search query</param> /// <param name="minimumConfidence">Minimum confidence by which to filter the search results</param> /// <param name="userPosition">User's location that is used to improve search results</param> /// <returns></returns> public static async Task<List<Location>> GetLocationByQuery(string query, Confidence minimumConfidence, OneBusAway.Model.Point userPosition) { if (string.IsNullOrEmpty(query)) { throw new ArgumentNullException(query); } Dictionary<string, string> queryParameters = Helpers.GetBasicParameters(); queryParameters.Add(UtilitiesConstants.Parameter_Query, query); if (userPosition != null) { queryParameters.Add(UtilitiesConstants.Parameter_UserLocation, userPosition.Latitude + "," + userPosition.Longitude); } string url = Helpers.CreateServiceUrl(UtilitiesConstants.BingLocationServiceBaseAddress, queryParameters); Response response = await Helpers.GetJsonResponse<Response>(url); return Helpers.FilterResults<Location>(response, minimumConfidence); }
/// <summary> /// Returns a list of suggestions for the user the OBA list of routes. /// </summary> public async Task<IEnumerable<string>> GetSuggestionsAsync(string query, OneBusAway.Model.Point userLocation) { var obaDataAccess = ObaDataAccess.Create(); var listOfAllRoutes = await obaDataAccess.GetAllRoutesForCurrentRegionAsync(); return from result in listOfAllRoutes where (result.ShortName != null && result.ShortName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) || (result.Description != null && result.Description.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) select string.Format(CultureInfo.CurrentCulture, "BUS {0}", result.ShortName); }
/// <summary> /// Searches all agencies for all bus numbers. /// </summary> public async Task SearchAsync(string query, OneBusAway.Model.Point userLocation) { this.NoSearchResultsText = string.Format(CultureInfo.CurrentCulture, "SEARCHING FOR '{0}'", query); try { if (string.IsNullOrEmpty(query)) { this.SearchResults.Clear(); this.BingMapsSearchResults = null; } else { // If the user selected a suggestion, then that means they want a specific bus: if (query.StartsWith("BUS", StringComparison.OrdinalIgnoreCase)) { await DisplayAndSelectSpecificRouteAsync(query.Substring(3).Trim()); } else { var listOfAllRoutes = await this.LoadAllRoutesAsync(); // Let's filter the results! var newItems = (from result in listOfAllRoutes where (result.ShortName != null && result.ShortName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) || (result.Description != null && result.Description.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) select new SearchRouteResultViewModel(result)); await this.uiHelper.BatchAddItemsAsync(this.searchResults, newItems); var bingMapResults = await BingMapsServiceHelper.GetLocationByQuery(query, Utilities.Confidence.Medium, userLocation); this.BingMapsSearchResults = (from result in bingMapResults select new SearchLocationResultViewModel(result)).ToArray(); } } } catch { } this.NoSearchResultsText = "NO RESULTS"; }