我创建了一个WPF应用程序,用于根据输入的关键字查找位置。为此,我使用了bing maps service api,我的代码是
private object 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 = "my 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;
}
}
这个应用程序。我在致电SearchKeywordLocation("sushi; Arvada, CO");
时收到了结果,但我的要求是在致电SearchKeywordLocation("new");
时获得结果我应该得到与纽约有关的结果。应避免使用此特定字符串格式。我在这里做错了什么?
答案 0 :(得分:0)
搜索服务是针对兴趣点而非地址。纽约属于地址类别,应该通过地理编码服务传递。也就是说,将“新”传递到任何服务中将不同于获得您想要的结果,因为有数百万可能的结果在其名称中包含“新”一词。鉴于此,地理编码器可能会发现这是一个形成不良的查询并将可能的结果限制为少数(测试“新”我看到5个结果,纽约不是其中之一)。
也就是说,您还应该避免使用旧的旧SOAP服务。它们已接近尾声,几年前文档已脱机。实际上,我们大约5年前就停止推荐SOAP服务,并且只为那些在其上运行旧应用程序的客户保留它们。 5年前,Bing Maps服务取代了这些服务,这些服务具有更多特性和功能,速度更快,响应对象更小,并且可以返回更准确的结果。您可以在此处找到有关使用REST服务的文档:https://msdn.microsoft.com/en-us/library/ff701713.aspx
以下是一些在.NET中使用它们的文档:https://msdn.microsoft.com/en-us/library/jj819168.aspxI
我一直在努力创建一个很好的.NET库来包装服务,使它们更容易在这些类型的应用程序中使用。如果您有兴趣测试一下,请发送电子邮件至hotmail.com的ricky_brundritt,我会发给您一份图书馆的副本。