Exemple #1
0
        /// <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(Constants.Parameter_Query, query);

            if (userPosition != null)
            {
                queryParameters.Add(Constants.Parameter_UserLocation, userPosition.Latitude + "," + userPosition.Longitude);
            }

            string url = Helpers.CreateServiceUrl(Constants.BingLocationServiceBaseAddress, queryParameters);

            Response response = await Helpers.GetJsonResponse <Response>(url);

            return(Helpers.FilterResults <Location>(response, minimumConfidence));
        }
 /// <summary>
 /// Utility method converts a point to a geocoordinate.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public static GeoCoordinate ToCoordinate(this OneBusAway.Model.Point point)
 {
     return(new GeoCoordinate(point.Latitude, point.Longitude));
 }