是的,我对此很陌生,所以我不能真正理解 Bing 提供的所有文档。但是,如果我有一个经度和纬度的双(数字)值,那么如何在 C# 中获得最近的位置,最好是字符串?我从旧教程中知道如何在 MSRMaps 中执行此操作,但我完全不知道如何在这里执行此操作。
非常感谢!
编辑:我在这里找到了本教程:http: //msdn.microsoft.com/en-us/library/dd221354.aspx
我决定只使用反向地理编码位,这就是我得到的:
static void Main(string[] args)
{
string location;
location = ReverseGeocodePoint("47.608, -122.337");
Console.WriteLine(location);
}
static string ReverseGeocodePoint(string locationString)
{
string results = "";
string key = "Aq4VS_9C4juJKsP7hRFqWlYj0Mpd_ybl2vOmj_J9rugPvptWiOEa3tCzmXWvzm9J";
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;
}
}
只有我在 GeocodeServiceClient 遇到错误 geocodeService = new GeocodeServiceClient();
说:无法加载合同“GeocodeService.IGeocodeService”的端点配置部分,因为找到了该合同的多个端点配置。请按名称指明首选端点配置部分。
这对我意味着什么?