public IEnumerable<string> SearchKeywordLocation(string keyword, double latitude, double longitude)
        {
            var results = new List<string>();

            var searchRequest = new SearchRequest();

            // Set the credentials using a valid Bing Maps key
            searchRequest.Credentials = new SearchService.Credentials();
            searchRequest.Credentials.ApplicationId = GetBingMapsApplicationKey();

            //Create the search query
            var ssQuery = new StructuredSearchQuery();
            ssQuery.Keyword = keyword;
            ssQuery.Location = string.Format("{0}, {1}", latitude, longitude);
            searchRequest.StructuredQuery = ssQuery;

            //Make the search request 
            SearchResponse searchResponse;
            using (var searchService = new SearchServiceClient("BasicHttpBinding_ISearchService"))
            {
                searchResponse = searchService.Search(searchRequest);
            }

            foreach (var searchResult in searchResponse.ResultSets[0].Results)
            {
                results.Add(string.Format("{0} ({1})", searchResult.Name, searchResult.Distance));
            }
            return results;
        }
Example #2
0
        public IEnumerable <string> SearchKeywordLocation(string keyword, double latitude, double longitude)
        {
            var results = new List <string>();

            var searchRequest = new SearchRequest();

            // Set the credentials using a valid Bing Maps key
            searchRequest.Credentials = new SearchService.Credentials();
            searchRequest.Credentials.ApplicationId = GetBingMapsApplicationKey();

            //Create the search query
            var ssQuery = new StructuredSearchQuery();

            ssQuery.Keyword  = keyword;
            ssQuery.Location = string.Format("{0}, {1}", latitude, longitude);
            searchRequest.StructuredQuery = ssQuery;

            //Make the search request
            SearchResponse searchResponse;

            using (var searchService = new SearchServiceClient("BasicHttpBinding_ISearchService"))
            {
                searchResponse = searchService.Search(searchRequest);
            }

            foreach (var searchResult in searchResponse.ResultSets[0].Results)
            {
                results.Add(string.Format("{0} ({1})", searchResult.Name, searchResult.Distance));
            }
            return(results);
        }
Example #3
0
        //The Search Service

        private string SearchKeywordLocation(string keywordLocation)
        {
            String        results       = "";
            String        key           = "ApwndqJgdJ9M1Bpb7d_ihBwXW-J0N3HdXrZvFZqvFtmeYN5DewRoGPI7czgFo5Sh";
            SearchRequest searchRequest = new SearchRequest();

            // Set the credentials using a valid Bing Maps key
            searchRequest.Credentials = new ServiceService.Credentials();
            searchRequest.Credentials.ApplicationId = key;

            //Create the search query
            StructuredSearchQuery ssQuery = new StructuredSearchQuery();

            string[] parts = keywordLocation.Split(';');
            ssQuery.Keyword  = parts[0];
            ssQuery.Location = parts[1];
            searchRequest.StructuredQuery = ssQuery;

            //Define options on the search
            searchRequest.SearchOptions         = new SearchOptions();
            searchRequest.SearchOptions.Filters =
                new FilterExpression()
            {
                PropertyId      = 3,
                CompareOperator = CompareOperator.GreaterThanOrEquals,
                FilterValue     = 8.16
            };

            //Make the search request
            SearchServiceClient searchService  = new SearchServiceClient("BasicHttpBinding_ISearchService");
            SearchResponse      searchResponse = searchService.Search(searchRequest);

            //Parse and format results
            if (searchResponse.ResultSets[0].Results.Length > 0)
            {
                StringBuilder resultList = new StringBuilder("");
                for (int i = 0; i < searchResponse.ResultSets[0].Results.Length; i++)
                {
                    resultList.Append(String.Format("{0}. {1}\n", i + 1,
                                                    searchResponse.ResultSets[0].Results[i].Name));
                }

                results = resultList.ToString();
            }
            else
            {
                results = "No results found";
            }

            return(results);
        }
Example #4
0
        public string SearchKeywordLocation(string keywordLocation)
        {
            String results = "";

            SearchRequest searchRequest = new SearchRequest();

            // Set the credentials using a valid Bing Maps key
            searchRequest.Credentials = new SearchService.Credentials();
            searchRequest.Credentials.ApplicationId = key;

            //Create the search query
            StructuredSearchQuery ssQuery = new StructuredSearchQuery();
            string[] parts = keywordLocation.Split(';');
            ssQuery.Keyword = parts[0];
            ssQuery.Location = parts[1];
            searchRequest.StructuredQuery = ssQuery;

            //Define options on the search
            searchRequest.SearchOptions = new SearchOptions();
            searchRequest.SearchOptions.Filters =
                new FilterExpression()
                {
                    PropertyId = 3,
                    CompareOperator = CompareOperator.GreaterThanOrEquals,
                    FilterValue = 8.16
                };

            //Make the search request
            SearchServiceClient searchService = new SearchServiceClient("BasicHttpBinding_ISearchService");
            SearchResponse searchResponse = searchService.Search(searchRequest);

            //Parse and format results
            if (searchResponse.ResultSets[0].Results.Length > 0)
            {
                StringBuilder resultList = new StringBuilder("");
                for (int i = 0; i < searchResponse.ResultSets[0].Results.Length; i++)
                {
                    resultList.Append(String.Format("{0}. {1}\n", i + 1,
                        searchResponse.ResultSets[0].Results[i].Name));
                }

                results = resultList.ToString();
            }
            else
                results = "No results found";

            return results;
        }