我正在搞乱Bing Maps WPF控件和SOAP服务,试图反转地理编码点。我尝试从this project实现一些代码,特别是这段代码:
private string ReverseGeocodePoint(string locationString)
{
string results = "";
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
// Set the credentials using a valid Bing Maps key
reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
reverseGeocodeRequest.Credentials.ApplicationId = key;
// Set the point to use to find a matching address
GeocodeService.Location point = new GeocodeService.Location();
string[] digits = locationString.Split(';');
point.Latitude = double.Parse(digits[0].Trim());
point.Longitude = double.Parse(digits[1].Trim());
reverseGeocodeRequest.Location = point;
// Make the reverse geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient();
GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);
if (geocodeResponse.Results.Length > 0)
results = geocodeResponse.Results[0].DisplayName;
else
results = "No Results found";
return results;
}
然而,当我尝试实现它时,我被告知:Error: The type or namespace name 'Credentials' does not exist in the namespace 'GeocodeTest.GeocodeService' (are you missing an assembly reference?)
此错误发生在该行:
reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
好奇,我决定通过对象浏览器查看服务引用。显然,我的GeocodeService
甚至没有Credentials
成员。所以现在的问题是:
答案 0 :(得分:2)
服务引用Credentials
不存在GeocodeText.GeocodeService
命名空间/类型。相反,您必须使用Bing Maps WPF Control中的Credentials
。声明如下:
reverseGeocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials();