在C#中,如何根据经纬度值从Bing地图中获取最近的位置?

在C#中,如何根据经纬度值从Bing地图中获取最近的位置?,c#,latitude-longitude,bing-maps,C#,Latitude Longitude,Bing Maps,是的,我对这个很陌生,所以我不能真正理解Bing提供的所有文档。 但是如果我有一个经度和纬度的双(数字)值,那么我如何才能得到最近的位置,最好是以字符串的形式,在C#中?我从以前的教程中知道如何在MSRMaps中实现这一点,但我完全不知道如何在这里实现这一点 多谢各位 编辑: 我在这里找到了本教程: 我决定只使用反向地理编码,这就是我得到的: static void Main(string[] args) { string location; locati

是的,我对这个很陌生,所以我不能真正理解Bing提供的所有文档。 但是如果我有一个经度和纬度的双(数字)值,那么我如何才能得到最近的位置,最好是以字符串的形式,在C#中?我从以前的教程中知道如何在MSRMaps中实现这一点,但我完全不知道如何在这里实现这一点

多谢各位

编辑: 我在这里找到了本教程:

我决定只使用反向地理编码,这就是我得到的:

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=新的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>


我应该在推荐信中写些什么?它少了一些,我不知道应该放什么进去。或者,是否有一个完整的项目,我可以看看?对我来说,复制和粘贴从来都不起作用。谢谢。你必须获得Bing API库。转到Bing并搜索Map API(SDK)等。是的,结果是一个字符串,单击我答案中的链接,您将看到完整的代码示例以及从何处获取SDK