在Bingmaps上从纬度和经度获取位置数据出错
本文关键字:获取 位置 置数据 出错 经度 Bingmaps 纬度 | 更新日期: 2023-09-27 18:15:34
我使用Bingmaps API获取AdminDistrict和CountryRegion的经度和纬度。它可以在浏览器中输入以下url:
http://dev.virtualearth.net/REST/v1/Locations/-30, -70/? includeEntityTypes = AdminDivision1 CountryRegion& o = xml& c = es-ES&关键= 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与web浏览器上的url相同。会出什么问题呢?
可能你已经想到了解决方案但在谷歌上搜索我发现了这个主题解决方案是不像你那样通过url发送密钥,而是将其作为参数添加到请求中,像这样:
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");
如果我理解正确的话,那么您使用的REST API可能需要花钱。也许您的API密钥没有为可计费的交易设置?
关于Location API的计费页面:
*如果它发生在AJAX控件或Silverlight控件会话的上下文中,则该类别是不计费的。
也许浏览器算AJAX控件,而手机并不是真正的"Silverlight控件"。