0

是的,我对此很陌生,所以我不能真正理解 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”的端点配置部分,因为找到了该合同的多个端点配置。请按名称指明首选端点配置部分。

这对我意味着什么?

4

2 回答 2

1

尝试从这里开始。地理编码服务特别是您正在寻找的是反向地理编码

根据 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;
于 2012-09-06T20:02:12.133 回答
0

您必须从 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>
于 2013-03-01T11:49:56.113 回答