[英]In C#, how do I get a nearest place from Bing Maps from a longitude and latitude value?
是的,我對此很陌生,所以我無法真正理解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'的端點配置部分,因為找到了該合同的多個端點配置。 請按名稱指示首選端點配置部分。
這對我意味着什么?
嘗試從這里開始。 地理編碼服務特別是您要尋找的是反向地理編碼
按照MSDN上的示例。
// Set a Bing Maps key before making a request
string key = "Bing Maps Key";
GeocodeService.ReverseGeocodeRequest reverseGeocodeRequest = new GeocodeService.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();
point.Latitude = 47.608;
point.Longitude = -122.337;
reverseGeocodeRequest.Location = point;
// Make the reverse geocode request
GeocodeService.GeocodeServiceClient geocodeService =
new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
GeocodeService.GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);
Results = geocodeResponse.Results[0].DisplayName;
您必須從App.Config / web.config中刪除其中一個端點
原始生成
<client>
<endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
contract="Microsoft.Bing.GeocodeService.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
<endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc/binaryHttp"
binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
contract="Microsoft.Bing.GeocodeService.IGeocodeService" name="CustomBinding_IGeocodeService" />
</client>
如果您從app.config / web.config中刪除端點配置之一,您的代碼將可以正常工作。
<client>
<endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
contract="Microsoft.Bing.GeocodeService.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
</client>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.