gpt4 book ai didi

c# - 在 Bing map 上从纬度和经度获取位置数据时出错

转载 作者:行者123 更新时间:2023-11-30 22:33:28 26 4
gpt4 key购买 nike

我正在使用 Bingmaps API 获取纬度和经度的 AdminDistrict 和 CountryRegion。它可以在浏览器中输入此 url:

http://dev.virtualearth.net/REST/v1/Locations/-30,-70/?includeEntityTypes=AdminDivision1,CountryRegion&o=xml&c=es-ES&key= myBingmapsApiKey

但是在 WP7 上的 C# 中,我无法让它工作。这是代码:

string wsUrl = "http://dev.virtualearth.net/REST/v1/Locations/-30,-70/?includeEntityTypes=AdminDivision1,CountryRegion&o=xml&c=es-ES&key=*myBingmapsApiKey*";

var request = new RestSharp.RestRequest(Method.GET);
var client = new RestSharp.RestClient(wsUrl);

try
{
RestSharp.RestResponse resource;
client.ExecuteAsync(request, (response) =>
{
resource = response;
string content = resource.Content;
string status_code = resource.StatusCode.ToString();
string response_status = resource.ResponseStatus.ToString();
});
}
catch (Exception e)
{
string error = "Error: " + e.ToString() + "\n. Stack Trace: " + e.StackTrace;
}

响应是:

    <?xml version="1.0" encoding="utf-8"?>
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">
<Copyright>Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
<BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
<StatusCode>401</StatusCode><StatusDescription>Unauthorized</StatusDescription>
<AuthenticationResultCode>InvalidCredentials</AuthenticationResultCode>
<ErrorDetails><string>Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation.</string></ErrorDetails>
<TraceId>59ebcf604bb343d79a6e8b93ad5695fe|MIAM001452|02.00.71.1600|</TraceId>
<ResourceSets />
</Response>

该 url 与在网络浏览器上工作的相同。有什么问题吗?

最佳答案

可能在这一点上你已经想出了一个解决方案,但在谷歌上搜索我发现了这个主题,解决方案是不像你那样通过 url 发送 key ,而是将它作为参数添加到请求中,如下所示:

string wsUrl = "http://dev.virtualearth.net/REST/v1/Locations/-30,-70/";    

var request = new RestSharp.RestRequest(Method.GET);
request.AddParameter("includeEntityTypes", "AdminDivision1,CountryRegion");
request.AddParameter("key", myLey);
request.AddParameter("o", "xml");

关于c# - 在 Bing map 上从纬度和经度获取位置数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8262151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com