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



我们正在使用地理编码服务来获取地理编码器(纬度/经度(,但是我们得到了"未找到服务方法"错误。以下是我的代码。

 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地图地图

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

看起来您正在尝试使用去年被弃用并关闭的旧虚拟地球肥皂服务。这些由7或8年前的Bing Maps Rest Services取代。由于您在.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.
}

相关内容

最新更新