在 Bing 地图中获取 "The service method is not found error"

Getting "The service method is not found error" in Bing Maps

我们正在使用地理编码服务获取 geocodeAddress (latitude/longitude),但我们收到了 "The service method is not found" 错误。下面是我的代码。

 public static double[] GeocodeAddress(string address, string virtualearthKey)
        {
            net.virtualearth.dev.GeocodeRequest geocodeRequest = new net.virtualearth.dev.GeocodeRequest
            {
                // Set the credentials using a valid Bing Maps key
                Credentials = new net.virtualearth.dev.Credentials { ApplicationId = virtualearthKey },
                // Set the full address query
                Query = address                
            };

            // Set the options to only return high confidence results 
            net.virtualearth.dev.ConfidenceFilter[] filters = new net.virtualearth.dev.ConfidenceFilter[1];
            filters[0] = new net.virtualearth.dev.ConfidenceFilter
            {
                MinimumConfidence = net.virtualearth.dev.Confidence.High
            };

            // Add the filters to the options
            net.virtualearth.dev.GeocodeOptions geocodeOptions = new net.virtualearth.dev.GeocodeOptions { Filters = filters };
            geocodeRequest.Options = geocodeOptions;

            // Make the geocode request
            net.virtualearth.dev.GeocodeService geocodeService = new net.virtualearth.dev.GeocodeService();
            net.virtualearth.dev.GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
            {
                return new[] { geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude };
            }

            return new double[] { };
        } // GeocodeAddress

密钥用于 URL bing 地图地理编码服务 we.config

<add key="net.virtualearth.dev.GeocodeService" value="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc" />

您似乎在尝试使用旧的 Virtual Earth SOAP 服务,该服务已于去年弃用并关闭。这些在 7 或 8 年前被 Bing Maps REST 服务所取代。由于您在 .NET 中工作,请查看 Bing Maps .NET REST 工具包。它使在 .NET 中使用 REST 服务变得容易。还有一个 NuGet 包可用。您可以在此处找到详细信息:https://github.com/Microsoft/BingMapsRESTToolkit

将 NuGet 包添加到项目后,您可以像这样进行地理编码:

//Create a request.
var request = new GeocodeRequest()
{
    Query = "New York, NY",
    IncludeIso2 = true,
    IncludeNeighborhood = true,
    MaxResults = 25,
    BingMapsKey = "YOUR_BING_MAPS_KEY"
};

//Execute the request.
var response = await request.Execute();

if(response != null && 
    response.ResourceSets != null && 
    response.ResourceSets.Length > 0 && 
    response.ResourceSets[0].Resources != null && 
    response.ResourceSets[0].Resources.Length > 0)
{
    var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;

    //Do something with the result.
}